Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Marr on Sun 06/06/2010 13:59:03

Title: Problem with 'if' function
Post by: Marr on Sun 06/06/2010 13:59:03
I'm having trouble trying to figure out some scripting using an 'if' function. My intention is that if one object's visibility is turned off by a mouse click that this will trigger another item's visibility to turn on. I've been scanning through the video tutorials for some guidance, as I recalled seeing if functions being used there, and I've had a look through the AGS wiki too. I'm probably missing something, but any help would be really appreciated.

My code looks like this:

Quote
function carkeys_AnyClick()
{
carkeys.Visible = false;

if (carkeys.Visible = false){
carkeyicon.visible = true;}
}

I tried to run this code but the error I get is

Quote
Error (line 33): Parse error in expr near 'carkeys'

The thing is, I'm not sure what that even means.
Title: Re: Problem with 'if' function
Post by: Dualnames on Sun 06/06/2010 14:03:31

function carkeys_AnyClick(){
carkeys.Visible = false;

if (carkeys.Visible == false){
carkeyicon.visible = true;
}
}


When you put = to an if statement it should be ==
The code above should work fine.

I'd ditch the if statement though because you always set the visible to false therefore before the if statement is run carkeys will always be off. But well, anyway.
Title: Re: Problem with 'if' function
Post by: Atelier on Sun 06/06/2010 14:09:22
Also remember that == checks a statement, = sets a statement.
Title: Re: Problem with 'if' function
Post by: Dualnames on Sun 06/06/2010 14:16:45
Also parse errors are mostly concerning syntax thingies.
Also just noticed shouldn't the carkeyicon. visible =true; , be carkeyicon.Visible=true;?
Title: Re: Problem with 'if' function
Post by: Marr on Sun 06/06/2010 14:40:52
Thank you guys! It works like a charm and I'll certainly keep the tip about the = marks in mind.