Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by grossim · Jun 25, 2017 at 09:33 AM · unity 5javascriptmultidimensional array

Can't access specific element in multidimensional array (JavaScript)

Hello, i cannot access a specific element in a multidimensional array, all i have in return when i debug is an empty object ( [ ] ).

This is what i am doing:

1- create a series of scores formed of two elements ( a numeric a string ("1.0, 1.2, 1.6, 0.7" etc) and an integer number).

 var score1 = [string,number];    for example ["1.0, 1.2, 1.6, 0.7 " , 154]
 var score2 = [string,number];
 var score3 = [string,number];

...and so on.

I then group those score under another array:

 var scorepattern1 = [[score7],[score5],[score3]];
 var scorepattern2 = [[score6],[score4],[score2]];
 var scorepattern3 = [[score5],[score3],[score1]];

i create another array containing the pattern i created above:

 var scorepatternlibrary = [[scorepattern1], [scorepattern2], [scorepattern3]];

and finally i pick a random pattern:

 var scorepatternToUse = scorepatternlibrary[Math.floor(Math.random() * scorepatternlibrary.length)];

Now, in this example, let's assume the randomly chosen pattern is scorepattern 3. I want to access the score at index 2 ([score1]), and get the parameter at index 0 (the string), so "1.0,1.2,1.6, 0.7 ".

What i am doing is:

 Debug.Log(patternToUse[2[0]];

Am i doing wrong? What is the right sintax to access a specific value in an array located in another array? Is this approach the correct one?

P.S. I am using GameSpark CloudCode (that uses JS), but the sintax might be a bit different. I am also new to jscript so i might be using unconventional approaches...be patient!

Thanks for your help!

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by hexagonius · Jun 25, 2017 at 10:33 AM

The official Microsoft MSDN documentation helps a lot:

https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/arrays/jagged-arrays

Comment
Add comment · Show 3 · 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 grossim · Jun 25, 2017 at 10:56 AM 0
Share

$$anonymous$$y code is in Java, not C#, Is there a guide detailed as that one using js?

Thanks

avatar image hexagonius grossim · Jun 25, 2017 at 07:07 PM 0
Share

Not really. C# is the actual standard now and it's recommended to learn it. Not to hard co$$anonymous$$g from UnityScript. But this answer has examples and following the syntax you should be able to figure out how deeper accesses work

http://answers.unity3d.com/questions/54695/how-to-declare-and-initialize-multidimensional-arr.html

avatar image grossim · Jun 25, 2017 at 10:41 PM 0
Share

I am more confident with C# but the GameSparks service i use for the multiplayer features of my game rely on JS. Not much i can do on that side really.

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

163 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 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 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 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 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 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 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 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 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 avatar image

Related Questions

How to make a player move up then forward using ontrigger enter collider? 0 Answers

Top Down Game - Camera Follow Player and General Scripting Question 0 Answers

Why can't I move player's game piece on 2nd turn? 0 Answers

Unity doesn't recognize Java version on Mac 0 Answers

OnCollisonEnter2D Not Firing after checking collider 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