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 thaiscorpion · Jun 11, 2013 at 12:01 AM · javascriptarraynested

How to implement nested arrays correctly?

I'm trying to make a map creation system similiar to a risk strategy game, I want to store the data for each map in a group of nested arrays but I'm really bad with arrays and can't get them to work, here is what I would like to do (but doesn't work):

     map['maxPlayers'] = 2;
     map['platforms'] = Array;
     
     //Platform 1
     map['platforms'][0] = Array;
     map['platforms'][0]['ID'] = 1;
     map['platforms'][0]['ownerID'] = 1;
     map['platforms'][0]['type'] = 1;
     map['platforms'][0]['troopCount'] = 1;
     map['platforms'][0]['atkBonus'] = 1;
     map['platforms'][0]['defBonus'] = 1;
     map['platforms'][0]['proBonus'] = 1;
     map['platforms'][0]['nodes'] = 1;
     
     //Platform 2
     map['platforms'][1] = Array;
     map['platforms'][1]['ID'] = 1;
     map['platforms'][1]['ownerID'] = 1;
     map['platforms'][1]['type'] = 1;
     map['platforms'][1]['troopCount'] = 1;
     map['platforms'][1]['atkBonus'] = 1;
     map['platforms'][1]['defBonus'] = 1;
     map['platforms'][1]['proBonus'] = 1;
     map['platforms'][1]['nodes'] = 1;

This is what would be ideal for me but I can't get it to work, I's sure it's just some simple sintax problem I'm having but any help would be great thanks!

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
Best Answer

Answer by Benproductions1 · Jun 11, 2013 at 01:52 AM

Hello,

Ok, there are so many problems with what you are doing:
Fistly, you can't use a string to reference an item in an array. Only indecies work.
Secondly, you have to initialize Arrays, using "new Array()"
Thirdly, you can't add things to an array by setting a value to an I referenced index. Fourthly, you should never use "Array"s they are memory hungry and slow. Use generic lists instead. Fithly, for your purpose, I suggest using "Classes" instead of arrays/lists. Look them up and see their awesomeness!!!

Hope this helps,
Benproductions1

Comment
Add comment · Show 4 · 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 thaiscorpion · Jun 11, 2013 at 02:08 AM 0
Share

Thankyou very much I will take a look at what you recommended!

avatar image Benproductions1 · Jun 12, 2013 at 04:34 AM 0
Share

Please accept my answer then

avatar image thaiscorpion · Jun 16, 2013 at 01:30 AM 0
Share

Yes was just checking it was right for me :D and yes classes were just what I was looking for and it now works great thanks!

avatar image Benproductions1 · Jun 16, 2013 at 04:29 AM 0
Share

Good to hear :)

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

15 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

Related Questions

Sorting arrays? 1 Answer

How to delete new'd arrays? 2 Answers

what is the difference between a float[] and a float[,]? 1 Answer

How to set parents of all objects in an array? 1 Answer

Parse Array data to generate html 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