Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 mmuller · Dec 10, 2010 at 05:53 PM · 2djavascriptarray

Splitting into 2d array with JS

Hi All,

I have my highscores being returned from a php script and am able to split once on my pipe "|" character but then want to split that into a further 3 items splitting on a "," This will be so that I can layout the items in a nicely formatted manner.

I have tried using this code but it bails on compilation:

    //scoreSplit = scores.Split("|"[0]);
    scoreSplit arrayLists = scores.Split('|'[0]);
    var allArrays : String = new string[arrayLists.Count][];
    for(int i = 0; i < arrays.Length; i++)
        {
        allArrays[i] = arrayLists[i].Split(',');
        }
}

When I run it with the first line uncommented and the rest commented it works fine but obviously its only 1d.

Any help would be appreciated as to where I am going wrong :)

regards,

mm

Comment
Add comment · Show 2
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 Eric5h5 · Dec 10, 2010 at 06:19 PM 0
Share

That code is C#, not JS.

avatar image Statement · Dec 10, 2010 at 08:53 PM 0
Share

That code is a mix.

1 Reply

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by skovacs1 · Dec 10, 2010 at 06:54 PM

You have more problems than lines of code:

  1. In the uncommented version you try to use a character literal, something for which there is no syntax in Unity js - you should use a indexed character from a String literal like you did in the commented version.
  2. What the heck are scoresplit and arrayLists and how are they related?! If it is a variable, in unity js, you need to use the var keyword and a name, providing static type indication with a colon(:).
  3. You statically type allArrays to be a String and then assign it an array of string.
  4. string is not a valid type in Unity js. You probably meant String.
  5. String[] does not have any member Count. Did you mean length?
  6. You try to declare built-in arrays without a size and this won't work even if there was a proper syntax for 2D arrays in Unity js.
  7. Your for loop is checking against some undefined variable arrays.
  8. Again, like 2., what the heck is i? See 2. for how to resolve this.
  9. If arrays was supposed to be some kind of array, there is no member Length for Unity js arrays. Did you mean length?
  10. Like 1., because there is no syntax for a character literal in Unity js, this will not work. See 1. for how to resolve this.
  11. For lack of a proper syntax for 2d arrays, Unity js is interpreting your attempt to assign the second dimension of a 2d array of strings as you trying to assign a character to that index of a string at that index in the array. Essentially, the point is that Unity js doesn't do built-in 2D arrays unless they were declared in c#. You will need to use jagged dynamic Unity js Array to accomplish your goals.

Working code would look like:

var arrayLists : String[] = scores.Split("|"[0]);
var allArrays : Array = new Array();
for(var i : int = 0; i < arrayLists.length; i++)
    allArrays[i] = arrayLists[i].Split(","[0])
Comment
Add comment · Show 1 · 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
avatar image mmuller · Dec 12, 2010 at 09:00 PM 0
Share

Skovacs, To the rescue again... what would I do without you. However, to save some embarassment from the cludge of code, I should have mentioned that the code above was bastardised from some other script I had seen elsewhere so I kind of knew it wouldn't be working and as stated I was asking for some help in getting it to do its thing :) So many many thanks for the advice about arrays in Unity JS and also the code example. You are a very kind person. regards, mm

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.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Need help with 2D Arrays (problems with navigating) 1 Answer

Creating a 2d array with the Array class 1 Answer

What type of Array should I use? 1 Answer

Moving an object with a collider in 2d? 1 Answer

How to remove null's from 2d array ? It's removing but only 2 out of 4 null's. 0 Answers


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