Hi my name is George I’m a beginner game developer, and a 3D artist here in Mexico.
This is my first post on the forum, nice to meet you all!
I’ve following Unity 3D Game Development by Example Beginner’s Guide book, and I have to say it is really good. However I’m stuck on a chapter 6. My code (at least to me) looks exactly the same to the book but i keep getting two Errors:
I hope any one with more knowledge can help me, and I excuse myself for any spelling errors.
Thanks!
2 Answers
2
You are missing a ‘}’ above your OnGUI(). You do not have a closing ‘}’ for your Start() function. Note in Monodevelop, you can position your cursor next to a ‘}’ or a ‘{’ and it will highlight the matching brace.
Yeah I’m sorry about that. Here it is again, thank you so much.
var cols:int = 4; // the number of columns in the card grid
var rows:int = 4; // the number of rows in the card grid
var totalCards:int = 16;
var matchesNeededToWin:int = totalCards * 0.5; // If there are 16 cards, the player needs to find 8 matches to clear the board
var matchesMade:int = 0; // At the outset, the player has not made any matches
var cardW:int = 100; // Each card's width and height is 100 pixels
var cardH:int = 100;
var aCards:Array; // We'll store all the cards we create in this Array
var aGrid:Array; // This array will keep track of the shuffled, dealt cards
var aCardsFlipped:ArrayList; // This array will store the two cards that the player flips over
var playerCanClick:boolean; // We'll use this flag to prevent the player from clicking buttons when we don't want him to
var playerHasWon:boolean = false; // Store whether or not the player has won. This should probably start out false :)
function Start()
{
playerCanClick = true; // We should let the player play, don't you think?
// Initialize the arrays as empty lists:
aCards = new Array();
aGrid = new Array();
aCardsFlipped = new ArrayList();
BuildDeck();
for(i=0; i<rows; i++)
{
aGrid *= new Array(); // Create a new, empty array at index i*
for(j=0; j<cols; j++)
- {*
- var someNum:int = Random.Range(0,aCards.length);*
_ aGrid*[j] = aCards[someNum];_
_ aCards.RemoveAt(someNum);_
_}_
_}*_
function OnGUI () //THE ERROR SHOWS HERE
{
* 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*[j];
if(GUILayout.Button(Resources.Load(card.img), GUILayout.Width(cardW)))
{
Debug.Log(card.img);
}
}
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
}
GUILayout.FlexibleSpace();
GUILayout.EndVertical();
}
class Card extends System.Object {
var isFaceUp:boolean = false;
var isMatched:boolean = false;
var img:String;*_
* function Card(img:String)*
* {*
* this.img = img;*
* }*
}
function BuildDeck()
{
* var totalRobots:int = 4; //we’ve got four robots to work with*
* var card:Object; // this stores a reference to a card*
}
for (i=0; i<totalRobots; i++)
{
}
for(i=0; i<totalRobots; i++)
{
* var aRobotParts:Array = [“Head”, “Arm”, “Leg”];*
}
for (i=0; i<totalRobots; i++)
{
* var aRobotParts:Array = [“Head”, “Arm”, “Leg”];*
* for (j=0; j<2; j++)*
* {*
* }*
}
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) + theMissingPart);*
* aCards.Add(card);*
* card = new Card (“robot” + (i+1) + theMissingPart);*
* aCards.Add(card);*
}
You did not post all the code. When you do, mark the line is some way. The line numbers reported by Unity and the line numbers here likely will not match.
– robertbuCould you post all code together?
– paulaceccon