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 /
avatar image
0
Question by bloodchylde · Sep 01, 2011 at 05:16 PM · arraysconvertbce0019bce0048

Convert Array

I'm trying to test this tutorial game on the adroid OS but the tutorial only seems to work on the PC/Web player builds. Now, I beleive my problem lies with my 3 arrays that I have in my script, because Android can't hand JS GUI arrays, and they need to be changed to C# arrays.. (if im understanding it right) SO my question is, how do change them? Im new to scripting and this is a little beyond me right now. I get errors when I try to compile for Android.. they say BCE0019 and BCE0048 ('item' not a memeber of object and object does not support slicing) Please help! Here is my script..

 void OnGUI (){

     GUILayout.BeginArea ( new Rect(0,0,Screen.width,Screen.height));

     BuildGrid();

     if(playerHasWon) BuildWinPrompt();

     GUILayout.EndArea();

     print("building grid!");

 }

 int cols = 4;

 int rows = 4;

 int totalCards = cols*rows;

 int matchesNeededToWin = totalCards * 0.50f;

 int matchesMade = 0;

 int cardW = 100;

 int cardH = 100;

 Array aCards;

 Array aGrid;

 ArrayList aCardsFlipped = new ArrayList();    

 bool  playerCanClick;

 bool  playerHasWon = false;

     

 void  BuildGrid (){

     GUILayout.BeginVertical();

     GUILayout.FlexibleSpace();

         for(i=0; i<rows; i++)

         {

     GUILayout.BeginHorizontal();

     GUILayout.FlexibleSpace();    

         for(j=0; j<cols; j++)

         {

             Object card = aGrid[i] [j];

             string img;

             if(card.isMatched)

             {

              img = "blank";

             }

             else

             if(card.isFaceUp)

             {

                 img = card.img;

             }

             else

             {

                 img = "wrench";

             }

             

             GUI.enabled = !card.isMatched;

             if (GUILayout.Button(Resources.Load(img),

                     GUILayout.Height(cardH),GUILayout.Width(cardW)))

                 {

                 if(playerCanClick)

                     {

                     FlipCardFaceUp(card);

                     Debug.Log(card.img);

                     }

                     

                 }

                 GUI.enabled = true;

             }

             GUILayout.FlexibleSpace();

             GUILayout.EndHorizontal();

             

             

             

         }

         

         GUILayout.FlexibleSpace();

         GUILayout.EndVertical();

     }

 



 

 

 

 void  Start (){

     playerCanClick = true;

     string[] aCards;

     string[] aGrid;

     aCardsFlipped = new ArrayList();

     

     BuildDeck();

     

     for(i=0; i<rows; i++)

     {

         aGrid[i] = new ArrayList();

     for(int j=0; j<cols; j++)

       {

           int someNum = Random.Range(0,aCards.length);

           aGrid[i] [j] = aCards[someNum];

           aCards.RemoveAt(someNum);

           }

       }

      }

      

 

 

     class Card extends System.Object

 {

     bool  isFaceUp = false;

     bool  isMatched = false;

     string img;

     int id;

     

     void  Card ( string img , int id  ){

         this.img = img;

         this.id = id;

         }

     }

 

 void  BuildDeck (){

     int totalRobots = 4;

     Card card;

     int id = 0;

 

 

     for(i=0; i<totalRobots; i++)

     {

     aRobotParts : string [] = ["Head", "Arm", "Leg"];

     for(j=0; j<2; j++)

     {

         int someNum = Random.Range(0, aRobotParts.length);

         string theMissingPart = aRobotParts[someNum];

         

         aRobotParts.RemoveAt(someNum);

         

         card = new Card("robot" + (i+1) + "Missing" + theMissingPart, id);

         aCards.Add(card);

         

         card = new Card("robot" + (i+1) + theMissingPart,id);

         aCards.Add(card);

         id++;

         }

     }

 }

 void  FlipCardFaceUp ( Card card  ){ 

         

     card.isFaceUp = true;

     if(aCardsFlipped.IndexOf(card) < 0)

     {

     aCardsFlipped.Add(card);

     

     if(aCardsFlipped.Count == 2)

     {

         playerCanClick = false;

         

         yield return new WaitForSeconds(1);

         if(aCardsFlipped[0].id == aCardsFlipped[1].id)

         {

         //MATCH!

         aCardsFlipped[0].isMatched = true;

         aCardsFlipped[1].isMatched = true;

         

         matchesMade ++;

         

         if(matchesMade >= matchesNeededToWin)

         {

             playerHasWon = true;

         }            

         }

         else

         {

         aCardsFlipped[0].isFaceUp = false;

         aCardsFlipped[1].isFaceUp = false;

         }

         

         aCardsFlipped = new ArrayList();

         

         playerCanClick = true;

         }

 }

 }

 

 void  BuildWinPrompt (){

 int winPromptW = 100;

 int winPromptH = 90;

 

 float halfScreenW = Screen.width/2;

 float halfScreenH = Screen.height/2;

 

 int halfPromptW = winPromptW/2;

 int halfPromptH = winPromptH/2;

 

 GUI.BeginGroup( new Rect(halfScreenW-halfPromptW,halfScreenH-halfPromptH,

 winPromptW, winPromptH));

 GUI.Box ( new Rect(0,0,winPromptW,winPromptH),

     "YOU WIN!");

 

 if(GUI.Button( new Rect(10,40,80,20), "Play Again?"))

 {

 Application.LoadLevel("Title");
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
1

Answer by Joshua · Sep 01, 2011 at 05:24 PM

You're absolutely right that you cannot use the 'Array' class, which is JS only - and also extremely slow so should be avoided even there if possible.

Instead you'll need to use normal, build-in, arrays. Have a look here, figure out the differences and change it - it's not that difficult but it's important you understand how they work.

Comment
Add comment · Show 13 · 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 bloodchylde · Sep 01, 2011 at 05:48 PM 0
Share

Ok, so as I said.. extremely new to this, like my first week.. so would it be like this? original var aRobotParts:Array = ["Head", "Arm", "Leg"];

changed Array aRobotParts = ["Head", "Arm", "Leg"];

but I need to change the variables associated with the array too right? format them different? I'm still kind of lost with the formatting.. I checked out that site...it is helpful. Thankyou.

avatar image Joshua · Sep 01, 2011 at 06:41 PM 0
Share

At the top, you have:

 var aCards:Array;

this is a javascript array, which are a huge pain because they are dynamically typed - so you don't know array of what type they are, or if they even contain only a single type.

from the context is seems aCards would be an array of strings, which would then be:

 var aCards : string[]; //js
 string[] aCards;       //c#

So, that means

 aRobot : Array = ["Head", "Arm", "Leg"];

becomes

 aRobot : string[] = ["Head", "Arm", "Leg"];
avatar image bloodchylde · Sep 02, 2011 at 07:46 PM 0
Share

ok, So i read that website a bunch, and researched some other sites, and tried to fix my code. Now I'm getting syntax errors at lines 2 and 3 for missing ; but theres already one there.. or it doesnt need one.. so now what am I doing wrong?? Is this script right with the arrays?? I tried to make it more in the c# then js.. But I don't know if I did it right. Reposting script in my original question..

avatar image SisterKy · Sep 02, 2011 at 08:23 PM 0
Share

that's strange. I don't see anything wrong with those lines of code. Have you tried restarting Unity (sometimes it helps...) If it's still complaining afterwards, please post the error-message. is it uce0001 or a cs-something?

avatar image bloodchylde · Sep 02, 2011 at 08:38 PM 0
Share

Hey again, well heres the errors:

Assets/GameScript.js(2,5): UCE0001: ';' expected. Insert a semicolon at the end. Assets/GameScript.js(2,14): UCE0001: ';' expected. Insert a semicolon at the end. Assets/GameScript.js(3,80): BCE0044: expecting :, found ';'.

Show more comments
avatar image
0

Answer by Sigil · Sep 03, 2011 at 07:30 AM

I'm a little confused by where the comments have gone with this one. So JavaScript Arrays aren't allowed for Android, isn't it possible to use ArrayList instead of converting everything over to C#?

I've looked around a bit, and I don't see a clear answer on this one, but it seems that the JavaScript Array class is the only special thing here, and all bloodchylde needs to do is convert those to ArrayLists instead, not even explicit arrays or anything.

Am I missing something?

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

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

6 People are following this question.

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

Related Questions

using char to extract integer numbers from a list - [UnityScript] 1 Answer

Could you help me convert this script to C#? 1 Answer

JS to C# conversion Problem 1 Answer

Android Compiler Errors 1 Answer

Convert string to guitext, in a guitext array. 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