- Home /
BCE0044: expecting }, found 'class' alond with BCE0044: expecting EOF, found 'Card'
I am going through a Unity3d book for beginners and I came accross something that I can't figure out. I recieve 2 errors when trying to run my game -
BCE0044: expecting }, found 'class' alond with BCE0044: expecting EOF, found 'Card'
Here is my script -
var cols:int = 4; var rows:int = 4; var totalCards:int = cols*rows; var matchesNeededTOWin:int = totalCards * 0.5; var matchesMade:int = 0; var cardW:int = 100; var cardH:int = 100; var aCards:Array; var aGrid:Array; var aCardsFlipped:ArrayList; var playerCanClick:boolean; var playerHasWon:boolean = false;
function Start () { playerCanClick = true; acards = new Array(); aGrid = new Array(); aCardsFlipped = new ArrayList();
BuildDeck();
for(i=0; i<rows; i++)
{
aGrid[i] = new Array() ;
for (j=0; j<cols; j++)
{
var someNum:int = Random.Range(0,aCards.length);
aGrid[i] [j] = aCards[someNum];
aCards.RemoveAt(someNum);
}
}
}
function OnGUI () { GUILayout.BeginArea (Rect (0,0,Screen.width,Screen.height)); BuildGrid(); GUILayout.EndArea(); print("building grid!"); }
function BuildGrid() { GUILayout.BeginVertical(); GUILayout.FlexibleSpace(); for(i=0; i<rows; i++) { GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); for(j=0; j<cols; j++) { var card:Object = aGrid[i] [j]; if(GUILayout.Button(Resources.Load(card.img), GUILayout.Width(cardW))) { Debug.Log(card.img); } } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } GUILayout.FlexibleSpace(); GUILayout.EndVertical(); }
function BuildDeck() { var totalRobots:int = 4; var card:Object; for (i=0; i<totalRobots; i++) { var aRobotParts:Array = ["Head", "Arm", "Leg"]; for (j=0; j<2; j++) { var someNum:int = Random.Range(0, aRobotParts.length); var theMissingPart:String = aRobotParts [someNum];
aRobotParts.RemoveAt(someNum);
card = new Card("robot" + (i+1) + "Missing" + theMissingPart);
aCards.Add(card);
card= new Card("robot" + (i+1) + theMissingPart);
aCards.Add(card);
}
}
class Card extends System.Object { var isFaceUp:boolean = false; var isMatched:boolean = false; var img:String;
function Card()
{
this.img = img;
}
}
From what I have read on other posts I either have to many '}' or not enough, but I don't think that is the case here since I have 2 open and 2 closing.
If I could get some help with this I would appreciate it very much!
Thanks
You can preview your posts here. So when you post a new question, make sure the code blocks are done right. You should edit it so that the code block is correct; it's easier for people to see what's going on then.
(I reformatted the code for you -- use the 01 icon for this.) The code shown looks fine -- is there something else in the file before the word "class"? What file extension does your script have?
Thank you for editing the format for me almo.
I was going to post my whole scropt but it looks all funny like the last time I copied and pasted it. How do you make it look correct on the post? Sorry this is the first question I have posted. I will post the whole script as soon as I can post it with the correct format. Thanks for your help - almo, yoyo, and GesterX
On $$anonymous$$e, the code button looks like 010 and 101 on two lines.
Answer by GesterX · May 15, 2011 at 05:10 PM
You need an additional curly bracket at the end of your BuildDeck function...
function BuildDeck() { var totalRobots:int = 4; var card:Object; for (i=0; i<totalRobots; i++) { var aRobotParts:Array = ["Head", "Arm", "Leg"]; for (j=0; j<2; j++) { var someNum:int = Random.Range(0, aRobotParts.length); var theMissingPart:String = aRobotParts [someNum];
aRobotParts.RemoveAt(someNum);
card = new Card("robot" + (i+1) + "Missing" + theMissingPart);
aCards.Add(card);
card= new Card("robot" + (i+1) + theMissingPart);
aCards.Add(card);
}
}
}
Your answer
Follow this Question
Related Questions
sript gets error 2 Answers
An EOF Problem :( 1 Answer
EOF error message 2 Answers
An EOF Problem :( (New) 3 Answers
script error GUI super simple code 3 Answers