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 Zachary Hoffman · Mar 20, 2014 at 02:44 AM · javascriptclasses

Basic Stuff on Arrays

I am learning from a book on unity and it used this

 var aGrid:Card[,];//2d array to keep track of the shuffled, dealt cards

I understand that :Cards means that it will only hold instances of the Cards class, but I don't understand what the comma in there means. There are no "," in my Card class. Can anyone explain what this does to me?

Here is the full code if you need it:

 #pragma strict
 
 class Card extends System.Object {
     var isFace:boolean = false;
     var isMatched:boolean = false;
     var img:String;
     
     function Card() {
         img = "robot";
     }
 }
 import System.Collections.Generic;
 var cols:int = 4; //number of collumbs
 var rows:int = 4; //the number of rows in a card grid
 var totalCards;int = 16;//4*4=16, there are sixteen slots in our grid for 16 cards
 var matchesNeededToWin:int =  totalCards * 0.5;//two cards is one match
 var matchesMade:int = 0;//At the outset, the player has not made any matches
 var cardW:int = 100; // Each card is 100px by 100px
 var aCards:List.<Card>;//We'll store all the cards we created in this list.
 var aGrid:Card[,];//2d array to keep track of the shuffled, dealt cards
 var aCardsFlipped:List.<Card>;//stores flipped cards
 var playerCanClick:boolean;//prevent players from clicking wrong buttons
 var playerHasWon:boolean = FalseString;//store wether or not the player has won
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 SirCrazyNugget · Mar 20, 2014 at 02:51 AM

It's to create a multidimensional array.

From what you've posted it looks like you're storing the address of each card, you could have an array of size 16 for each of the possible positions or a 2D array of 4x4 to supply the 16 possible addresses.

Using the 2D array enables to you to see the variable being stored at that address a lot easier Card[3,3] is the last address on the 4x4 grid instead of using Card[15].

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 Zachary Hoffman · Mar 20, 2014 at 03:05 AM 0
Share

Thanks so much!

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

20 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

Related Questions

Accessing a variable inside a class inside other script... 2 Answers

how to write classes 1 Answer

Array of custom class objects all return the same value? 1 Answer

Inventory Help. 2 Answers

How to create a Game Tree data structure in Unity. 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