Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: MrAbu on Wed 02/08/2017 01:05:29

Title: Parse error near expression near "object" in GlobalScript
Post by: MrAbu on Wed 02/08/2017 01:05:29
Code (ags) Select

function ckitty_Talk()
{
if (object[3].Visible = false) &&
(object[4].Visible = false)
{dkitty.Start();}

else if (object[3].Visible = true) &&
(object[4].Visible = false)
{dkittywantswater.Start();}

while (object[3].Visible = false) &&
(object[4].Visible = true)
{dkittywantsfood.Start();}

else Display("He looks busy.");
}



I'm working on a personal project of mine (it's about a cat). Basically I want one dialogue option for when neither of two objects are visible, then i want on option for when one of the objects is visible, and one for when the other is visible, but i keep getting a parse error at the beginning. I've been working on it for awhile now and i still can't figure out why. I'm still very new to this so any help would be appreciated.
Title: Re: Parse error near expression near "object" in GlobalScript
Post by: Snarky on Wed 02/08/2017 01:08:13
You have to use a double equals sign, "==" for checking if two things are equal. A single sign tries to set the thing on the left to the value on the right.
Title: Re: Parse error near expression near "object" in GlobalScript
Post by: MrAbu on Wed 02/08/2017 01:11:22
Oh wow, thank you so much. That fixed that problem, but now im getting an error at the "&&" The tutorial showed that as the command to use, but is there something else i should use?
Title: Re: Parse error near expression near "object" in GlobalScript
Post by: MrAbu on Wed 02/08/2017 01:17:54
Nevermind! I fixed it! I had to include both of the if statements in the same parenthesis, thanks for the help.
Title: Re: Parse error near expression near "object" in GlobalScript
Post by: Gurok on Wed 02/08/2017 01:20:28
There's also the matter of the while statement. I think you mean to use an if statement there. The while statement will loop over the statements inside it, in this case indefinitely looping over dkittywantsfood.Start(); if the condition is met.

If you wanted to, you could also rearrange the if statements to simplify things a bit:

Spoiler
function ckitty_Talk()
{
if(object[4].Visible)
{
if(object[3].Visible)
{
Display("He looks busy.");
}
else
{
dkittywantsfood.Start();
}
}
else
{
if(object[3].Visible)
{
dkittywantswater.Start();
}
else
{
dkitty.Start();
}
}
}
[close]

The code there should match your intention. It just doesn't necessarily do as many checks.
Title: Re: Parse error near expression near "object" in GlobalScript
Post by: MrAbu on Wed 02/08/2017 01:23:38
Yeah, i just caught the while statement issue, I was experimenting with different things i could do and i forgot to change that back. Oh cool! I didn't think about trying that! Thanks, that'll simplify things.

PS: this is my first time posting and i have to say , the community here is really cool.