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 StevenCalwas · Mar 01, 2012 at 04:28 AM · javascriptmultidimensional array

Multidimensional array in Javascript

I'm trying to get a multidimensional array working. I have:

 // Global variable grid of Cards (Cards is my own class)
 var aGrid : Cards[,];

 function Start(){
     // Init aGrid
     for( var i = 0; i < 4; ++i ){
         for( var j = 0; i < 4; ++i ){
             aGrid[ i, j ] = new Card();
         }
     }
 }

 function accessGrid(){
     // Try to access initialized aGrid
     // This bombs, saying aGrid is a null value
     var card : Card = aGrid[ intX, intY ];
 }


When I run the app, the accessing of aGrid fails saying aGrid is null, even though the intX and intY indexing variables are valid (i.e., are values between 0<4).

Didn't I initialize aGrid correctly in the Start() function? Do I need some type of aGrid = new Card[4,4]; statement?

Comment
Add comment · Show 1
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 flamy · Mar 01, 2012 at 11:08 AM 0
Share

if it is a fixed array give the size of it throught editor!

1 Reply

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

Answer by StevenCalwas · Mar 01, 2012 at 09:31 PM

Actually, while writing the original question, I came up with the correct answer. I added the statement:

 aGrid = new Card[ 4, 4 ];

to the Start() function and everything works.

Comment
Add comment · Show 8 · 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 wayneglows · Mar 21, 2013 at 01:54 AM 0
Share

Thanks for taking the time to post your answer to this, I am working though the same problem in the Unity book and was looking for a "#pragma strict" way to do this for the old 3.x code.

avatar image Benproductions1 · Mar 21, 2013 at 03:00 AM 0
Share

If this is the answer, please accept it so the question shows up as answered :)

avatar image wayneglows · Mar 21, 2013 at 03:04 AM 0
Share

I attempted to do that, but says I do not have permission. I am guessing there is some sort of waiting period before I can mark questions answered.

avatar image Benproductions1 · Mar 21, 2013 at 03:10 AM 0
Share

@_Gloam Only an Ad$$anonymous$$/$$anonymous$$oderator or the person who asked the question can accept an answer. $$anonymous$$y comment was towards @StevenCalwas

avatar image wayneglows · Mar 21, 2013 at 03:15 AM 0
Share

@Benproductions1 Gotcha, upvoting was giving me the trouble I suppose. Looks like I am short on karma AT$$anonymous$$.

Show more comments

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

8 People are following this question.

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

Related Questions

Why can't I push and pop from string array? 1 Answer

Entering Data into a 2d array overwrite issue. 1 Answer

Setting Scroll View Width GUILayout 1 Answer

Creating multidimensional string array 1 Answer

How to Create Dynamic Multidimensional Array? 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