Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: on Sun 14/03/2004 18:55:00

Title: parse error at "else"
Post by: on Sun 14/03/2004 18:55:00
Well, I was happily scripting away when this little wonder came up, I just can't work out what I've done wrong, this is where the problem is apparently:

-script beings-

function hotspot4_a() {
 // script for hotspot4: Interact hotspot
if (GetGlobalInt(2)==0)

SetGlobalInt (2, 1);
DisplaySpeech  (PZY , "what the hell is this and what is it doing in the sofa?");
AddInventory (4);

else

DisplaySpeech (PZY , "what are the odd's of finding TWO giant mushrooms in the sofa?");
}
 
-script ends-

don't ask me what's up with the giant mushroom, it makes sence in the game.

I realise it's probably something really painfully obvious, so thanks for your help.
Title: Re:parse error at "else"
Post by: Alynn on Sun 14/03/2004 19:45:59
if (GetGlobalInt(2)==0)
{
SetGlobalInt (2, 1);
DisplaySpeech (PZY , "what the hell is this and what is it doing in the sofa?");
AddInventory (4);
}
else
{
DisplaySpeech (PZY , "what are the odd's of finding TWO giant mushrooms in the sofa?");
}


If you are doing more than one line of code you need to define the code blocks with the braces { and }

I added the second set just because you ended the code with a brace but doing
else DisplaySpeech (PZY , "what are the odd's of finding TWO giant mushrooms in the sofa?");
would also be acceptable.
Title: Re:parse error at "else"
Post by: on Sun 14/03/2004 22:00:41
oh fantastic, thanks for the help.
Title: Re:parse error at "else"
Post by: Ginny on Sun 14/03/2004 22:04:48
Actually, the last brace belongs to the function, so make sure there are two braces at the end. Just pointing out. :)