Search Unity

Unknown Identifier error

Discussion in 'Scripting' started by sunstone124, Nov 21, 2014.

  1. sunstone124

    sunstone124

    Joined:
    Dec 11, 2012
    Posts:
    5
    I am getting a unknown identifier error when trying to change a variable with a GUI button. I don't know what is causing it because it should be recognized.
    Here is the code:
    Code (JavaScript):
    1. #pragma strict
    2. var gameDif = "Easy";
    3. var gameDifInternal = 1;
    4. function OnGUI () {
    5.     if (GUI.Button (Rect (820,400,300,200), "Difficulty: " + gameDif)){
    6.        gameDifInternal++;
    7.     }
    8.     if(gameDifInternal == 1){
    9.     gameDif = "Easy";
    10.     }
    11.     else if(gameDifInternal == 2){
    12.     gameDif = "Normal";
    13.     }
    14.     else if(gameDifInternal == 3){
    15.     gameDif = "Hard";
    16.     }
    17.     if(gameDifInternal == 4 || gameDifInternal > 3){
    18.     gameDif = "Easy";
    19.     gameDifInternal = 1;
    20.     }
    21. }
    . Please help!
     
  2. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,609
    Wrong section.
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The code you posted doesn't generate any errors. But you should use arrays instead of coding a bunch of separate if/then statements.

    --Eric
     
  4. sunstone124

    sunstone124

    Joined:
    Dec 11, 2012
    Posts:
    5
    The point is that it does create an error, but i don't know why it does. It gives an unknown identifier error at line 6. The problem is that I don't know why it is creating an error because the variable is defined.
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Except that it doesn't. I didn't see any issues with a quick scan, so I copied and pasted it into Unity, and no errors.

    --Eric
     
  6. sunstone124

    sunstone124

    Joined:
    Dec 11, 2012
    Posts:
    5
    Never mind, it was something else with the same variable name. Oops! Sorry about that. :p