• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by AyooNisto · Sep 29, 2013 at 03:47 PM · javascriptarraysarraylisttextfile

Type function(): Object[] does not support Slicing

I am loading text into an array from a text file. I know the array is being populated from when I debug the program, but when i attempt to output the information i get the error "Type function(): Object[] does not support Slicing." How do i go about fixing this? I will post my code below

 var returnChar = "\n"[0];
 var commaChar = ","[0];
  
 var dataLines = dataFile.text.Split(returnChar);
 var buildDataPairs = new ArrayList();
  
 for (var dataLine in dataLines) {
 var dataPair = dataLine.Split(commaChar);
 buildDataPairs.Add(dataPair);
 }
 var dataPairs = buildDataPairs.ToArray; 
 Debug.Log(dataPairs[0][0]);

 
Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image vexe · Sep 29, 2013 at 05:42 PM 0
Share

Not that it's related, but why use a string if you just need a char?

why var commaChar = ","[0]; and not var comma = ',';?

avatar image Jamora · Sep 29, 2013 at 05:44 PM 0
Share

That's how UnityScript does it, apparently. At least, according to the Unify Wiki

avatar image Eric5h5 · Sep 29, 2013 at 07:49 PM 0
Share

In Unityscript, both ' and " are used for strings. (One of those cases where Unityscript actually is like Javascript.) You need to reference chars by their index in a string. C# can also use that technique.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Eric5h5 · Sep 29, 2013 at 04:56 PM

Don't use ArrayList, it's slow, untyped, and obsolete. (Don't use the JS Array class either for the same reason.) Use generic Lists. Since buildDataPairs has no type, turning it into an array makes in an Object[] array, which you would need to cast in order to use.

Also you need to use ToArray() as a function, not ToArray. However, since you should make buildDataPairs into a List of String[], there's no real reason to turn it into an array, so you can just leave it as List.< String[] > and not bother with ToArray().

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

List problem? 2 Answers

Distance error: Cannot cast from source type to destination 0 Answers

Using a Parameterized arraylist (C#)??? 1 Answer

Get all GameObjects by variable value 2 Answers

Implicit downcast and ArrayList 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges