- Home /
Script Errors when nothing wrong...I think
Ok, I am a beginner, so it could likely be something I'm doing wrong, but I don't think so. I put the below script in Unity before and it worked, but now as I was editing stuff at the bottom (the About Game guiMode and the How to Play guiMode), it gave me these errors:
(17, 20 [ if(guiMode = "Main") ] ) - BCE0044: expecting ), found '=').
(17 22) - BCE0043: Unexpected token: Main.
(20, 17 [ just under //New Game Button ] ) - BCD0043: Unexpected token: if.
(20, 119) UCE0001: ';' expected. Insert a semicolon at the end.
(22, 61 [ PlayerPrefs.GetInt......] ) BCE0044: expecting :, found ';'.
#pragma strict
@script ExecuteInEditMode()
var myGUI : GUISkin;
var buttonWidth : float;
var guiMode : string = "Main";
function Start()
{
guiMode = "Main";
}
function OnGUI()
{
GUI.skin = myGUI;
if(guiMode = "Main")
{
// New Game
if(GUI.Button(Rect (Screen.width/2-(buttonWidth/2), Screen.height/2-20, buttonWidth, 30), "New Game"))
{
PlayerPrefs.GetInt("playerLevel", 1);
Debug.Log("New Game Clicked");
Application.LoadLevel(1);
}
// Continue Game
if(PlayerPrefs.HasKey("playerLevel"))
{
if(GUI.Button(Rect (Screen.width/2-(buttonWidth/2), Screen.height/2+20, buttonWidth, 30), "Continue Game"))
{
Application.LoadLevel(PlayerPrefs.GetInt("playerLevel"));
}
}
else
{
GUI.Box(Rect (Screen.width/2-(buttonWidth/2), Screen.height/2+20, buttonWidth, 30), "Continue Game");
}
//How to Play
if(GUI.Button(Rect (Screen.width/2-(buttonWidth/2), Screen.height/2+60, buttonWidth, 30), "How to Play"))
{
guiMode = "HowTo";
}
//About Game
if(GUI.Button(Rect (Screen.width/2-(buttonWidth/2), Screen.height/2+100, buttonWidth, 30), "About Game"))
{
guiMode = "About";
}
}
if(guiMode = "HowTo")
{
Debug.Log("How to Play");
//Back to Main Menu
if(GUI.Button(Rect (Screen.width/2-(buttonWidth/2), Screen.height/2+100, buttonWidth, 30), "About Game"))
{
Debug.Log("About Clicked");
}
}
if(guiMode = "About")
{
Debug.Log("About Game");
//Back to Main Menu
if(GUI.Button(Rect (Screen.width/2-(buttonWidth/2), Screen.height/2+100, buttonWidth, 30), "About Game"))
{
Debug.Log("About Clicked");
}
}
}
What am I doing wrong?
Alucardj is spot on, a single equal sign(=) is assignment, double equal sign(==) is comparison.
= is equal to
== is it equal to
On another note, the GetInt, you have it get "playerlevel" and you use a default value of 1, but you don't have that value assigned on line 22, which if that player preference was missing would return that 1, but it wouldn't set it. For that you would use SetInt
Yep that was it. I was wondering when I was supposed to use a == ins$$anonymous$$d of an =. Guess its time to do more reading!
Thanks man!
Answer by AlucardJay · Mar 19, 2013 at 12:59 PM
start with line 17 : your conditional only has one equals sign, it needs to say "is equal to" ==
if ( something == somethingElse )
if ( guiMode == "Main" )
the same goes for all your conditionals. Check the list of operators on this link : http://forum.unity3d.com/threads/173876-Programming-and-Making-Games-with-Unity-3D
Your answer
![](https://koobas.hobune.stream/wayback/20220613094708im_/https://answers.unity.com/themes/thub/images/avi.jpg)