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 silentApp · Feb 15, 2013 at 05:47 PM · errorbeginnertutorialbook

xpecting (, found 'OnGUI'

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!

Comment
Add comment · Show 2
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 robertbu · Feb 15, 2013 at 05:50 PM 1
Share

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.

avatar image paulaceccon · Feb 15, 2013 at 08:02 PM 0
Share

Could you post all code together?

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by robertbu · Feb 16, 2013 at 04:35 AM

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.

Comment
Add comment · Show 2 · 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 silentApp · Feb 16, 2013 at 07:18 AM 0
Share

Yeah, didn't noticed that, but when I add the '}' A new series o problems arise more like 10 to 12 new errors... Thanks a lot anyways :)

avatar image silentApp · Feb 16, 2013 at 07:49 AM 0
Share

BTW Thanks for the bracket tip, its helping a lot.

avatar image
0

Answer by silentApp · Feb 16, 2013 at 04:28 AM

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[i] = 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[i][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[i][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);
     }
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

10 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

Related Questions

Tutorial button doesn't work 0 Answers

Why is rigidbody.AddForce not working? 3 Answers

completely lost noob 1 Answer

Error on Line 28: expecting EOF found "}" 2 Answers

3D Platformer Tutorial - 5 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