- Home /
ShopScript.Js(49,17): BCE0044 expecting :, found GUI.
Hi i Get this error : ShopScript.Js(49,17): BCE0044 expecting :, found GUI. i cant seem why btw its not my script
var PlayerTalksToShopOwner : boolean = false; var OpenShopGUI : boolean = false; var Player : GameObject; var PlayerLevel : int = 0; var CashAmount : int = 0; var BackGroundPos : Vector2 = new Vector2(10,10); var BackGroundSize : Vector2 = new Vector2(10,10); var ShopContentPos : Vector2 = new Vector2(10,10); var ShopContentSize : Vector2 = new Vector2(10,10); var ButtonSize : Vector2 = new Vector2(10,10); var Button1Pos : Vector2 = new Vector2(10,10); var Button2Pos : Vector2 = new Vector2(10,10); var Price1 : int = 100; var Price2 : int = 200; var Price3 : int = 300; var Price4 : int = 400;
function Awake() { if (Player == null) { //use find with tag or any method you prefere to locate your player } }
function Update () { if (PlayerTalksToShopOwner == true) { CheckPlayersLevel (); OpenShopGUI = true; } }
function CheckPlayersLevel() { LVcheck = Player.GetComponent (PlayerScript); PlayerLevel = LVcheck.Level; CashAmount = LVcheck.Money; }
function OnGUI () { if (OpenShopGUI == true); { //Draw shop interface, start with the background GUI.BeginGroup (new Rect (BackGroundPos.x,BackGroundPos.y,BackGroundSize.x,BackGroundSize.y));
GUI.BeginGroup(new Rect (ShopContentPos.x,ShopContentPos.y,ShopContentSize.x,ShopContentSize.y));
//check the players level and open the right shop
if (PlayerLevel >= 0 && PlayerLevel <= 10)
{
//Draw buttons so that you can buy something
if (GUI.Button (new Rect (Button1Pos.x,Button1Pos.y,ButtonSize.x,ButtonSize.y)) && CashAmount >= Price1)
{
//add item you just bought to inventory
CheckMoney.Money = CheckMoney.Money - Price1;
}
if (GUI.Button (new Rect (Button2Pos.x,Button2Pos.y,ButtonSize.x,ButtonSize.y)) && CashAmount >= Price2)
{
//add item you just bought to inventory
CheckMoney.Money = CheckMoney.Money - Price2;
}
}
if (PlayerLevel >= 11 && PlayerLevel <= 20)
{
//Draw buttons so that you can buy something
if (GUI.Button (new Rect (Button1Pos.x,Button1Pos.y,ButtonSize.x,ButtonSize.y)) && CashAmount >= Price3)
{
//add item you just bought to inventory
CheckMoney.Money = CheckMoney.Money - Price3;
}
if (GUI.Button (new Rect (Button2Pos.x,Button2Pos.y,ButtonSize.x,ButtonSize.y)) && CashAmount >= Price4)
{
//add item you just bought to inventory
CheckMoney.Money = CheckMoney.Money - Price4;
}
}
}
}
Answer by Bunny83 · Apr 28, 2011 at 06:05 PM
Remove the semicolon at this line...
if (OpenShopGUI == true);
edit
Ok, I've just copied your script into my test project. I've created the two related scripts PlayerScript
and CheckMoney
. I've added a static var Money to the CheckMoney script. Now Unity just complains about your 4 Buttons. You've just set a Rect where the button should appear but you didn't supply the content. If you look at the scripting reference you will see that a button always needs either a string, a Texture or a GUIContent that is displayed on the button.
After i've added a string to each button all compiler errors are gone. I've never got that second error you mentioned. If you fix compiler errors always start with the first error. In most cases the first error will totally mess up the compiler and further errors will disappear after you fixed the first one.
You should get a bit more familiar with the syntax because that are first-month-mistakes...
Yes, it does work. Putting the semicolon there is incorrect syntax and will fail; removing it fixes the problem. You have other problems though.
When i remove the semicolon error : 31,27 :UCE0001 ";" expected. Insert a semicolon at the end
Your answer
Follow this Question
Related Questions
Script error. Please Help! 4 Answers
BCE0044: expecting ':' found ';' 1 Answer
Unity MoveAround error 1 Answer
3 java errors on a basic shooting script? 2 Answers
Gun recoil/hitback animation problem 1 Answer