[solved] Little problem with the IF function

Started by actaria, Sat 23/07/2022 09:29:23

Previous topic - Next topic

actaria

Hello,

I am kind of new to AGS, it's been a few month now and unfortunately i am struggling with the IF function.

Code: ags

function oObject1_Interact()
{
if (oObject1.Visible = true) {
player.Say("the door is closed");

}


This is the error message i got:
Failed to save room room10.crm; details below
room10.asc(77): Error (line 77): Parse error in expr near 'oObject1'


oObject1 does exist it's the door in closed position

Thanks in advance for you help i wish everyone a nice week-end.

Laura Hunt

#1
1. You haven't closed your if statement. You need another "}" symbol.
2. The "=" operator assigns values, but you need to use "==" to compare values.

Code: ags
function oObject1_Interact()
{
   if (oObject1.Visible == true) {
      player.Say("the door is closed");
   }
}


Also, it is advisable to indent your code, since it makes it easier to see issues like this one, and to give clearer names to your objects, so you know exactly what they are. For example, in this case, instead of oObject1, you could call it oDoorClosed.

actaria

#2
Hello and thanks a lot for the quick answer.

You are right i made a big mistake with the = operator instead of ==
I will also give clearer name to my object and rename it Odoorclosed that's a very good advice.

Thanks again for your precious help and now i will follow you on twitter  :)


actaria


SMF spam blocked by CleanTalk