• 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 Vetalyn · Dec 02, 2013 at 05:09 PM · arraysrobotslicing

Robot repair script, error bce0048

I've been getting several errors for this script, but I knocked it down to just this one, object' does not support slicing. Line 65,26. This question has been answered before, but the other answers haven't helped me on this part.

 #pragma strict
 var cols:int = 4;//the number of columns in the card grid 
 var rows:int = 4;//the number of rows in the grid
 var totalCards:int = cols*rows;
 var matchesNeededToWin:int = totalCards * 0.5;//8 matches are needed to clear the board
 var matchesMade:int = 0;//at the start the player hasn't made any matches
 var cardW:int = 100;//Each card's width is 100 pixels
 var cardH:int = 100;//Each card's height is 100 pixels
 var aCards:Array;// store the cards created in this array
 var aGrid:Array;//keep track of shuffled, dealt cards in this array
 var aCardsFlipped:ArrayList;//stores the two cards that the player flips over
 var playerCanClick:boolean;//use this flag to prevent player from clicking buttons at certain times
 var playerHasWon:boolean = false;//stores whether or not the player has won
 var i:int;
 var j:int;
 
 function Start () 
 {
   playerCanClick = true;
   
   //initialize the arrays as empty lists:
   aCards = new Array();
   aGrid = new Array();
   aCardsFlipped = new ArrayList();
   
   for(var i=0; i<rows; i++)
   {
     var acrds:Array=new Array();
     
    for(var j=0; j<cols; j++)
     {
      acrds[j] = new Card();
     }
     aGrid[j]=acrds;
   }
 }
 
 function OnGUI () 
 {
   GUILayout.BeginArea (Rect (0,0,Screen.width,Screen.height));//this will be the width and height of the screen and it will start at the screen origin
   BuildGrid();//builds the grid of card buttons
   GUILayout.EndArea();
   print("building grid!");
 }
 
 class Card extends System.Object
 {
  var isFaceUp:boolean = false; //determines whether or not the card has been flipped
  var isMatched:boolean = false;//is set to true when the card has been matched
  var img:String;
  
  function Card()
  {
    img = "robot";
  }
  
 }
 
   function BuildGrid()
 {
  GUILayout.BeginVertical();
  for(i=0; j<cols; j++)
  {
   GUILayout.BeginHorizontal();//BeginHorizontal/EndHorizontal to make card buttons stacked horizontally instead of vertically
   for(j=0; j<cols; j++)
   {
     var card:Card = aGrid[i];
     if(GUILayout.Button(Resources.Load(card.img),
         GUILayout.Width(cardW)))//keeps the card from filling the width of the layout area
     {
       Debug.Log(card.img);
     }
   }
   GUILayout.EndHorizontal();
  }
  GUILayout.EndVertical();
 }
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by KiraSensei · Dec 02, 2013 at 05:22 PM

aGrid is an Array, you try to access aGrid[i][j]. aGrid[i] is ok, but not aGrid[i][j]. aGrid should be of type Card[][].

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

Answer by tanoshimi · Dec 02, 2013 at 05:26 PM

Well, the problem is that aGrid is a one-dimensional Array(), but you're trying to access it using two-dimensional index notation: aGrid[i][j].

Unlike C#, Javascript does not support native multi-dimensional arrays, but you can use "jagged" arrays (i.e. arrays of arrays). I'm not sure exactly what the best solution is though because, in the absence of any comments, I'm not sure what you're trying to achieve.

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 Vetalyn · Dec 02, 2013 at 11:39 PM 0
Share

I'll update the script with the 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

18 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

Related Questions

Getting C# to access a javascript global Array and Components 1 Answer

How would I call upon an asset in the projects tab with an array? 1 Answer

adding classes to arrays 2 Answers

Array of variable-length arrays (JS) 1 Answer

help understanding and manipulating arrays 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