Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Wizzard on Mon 27/06/2011 23:08:13

Title: DoOnceOnly
Post by: Wizzard on Mon 27/06/2011 23:08:13
I'm getting odd results with the DoOnceOnly command. When using multiple Say scripts after DoOnceOnly not all Say commands show output. Is there a strict rule when using this command?
Title: Re: DoOnceOnly
Post by: Atelier on Mon 27/06/2011 23:10:34
Could you post your code please?
Title: Re: DoOnceOnly
Post by: Khris on Mon 27/06/2011 23:12:41
I'll go out on a limb and speculate: did you enclose all the Say commands properly in { and }?
But yeah, Y U NO POST CODE!?
Title: Re: DoOnceOnly
Post by: monkey0506 on Mon 27/06/2011 23:48:20
Yes, there's two very strict rules:

1: The function returns a boolean.
2: Normal programming logic applies.

If that doesn't clarify your problem, you might consider taking a look at the scripting tutorial in the manual.
Title: Re: DoOnceOnly
Post by: Wizzard on Tue 28/06/2011 17:46:52
Okay, whoops! No I didn't enclose all Say commands in seperate brackets {}.

the code goes something like this.

function code for walk on region.
{
if(DoOnceOnly(" unique token "))
cEgo.Say(" Blah Blah Blah ");
cEgo.Say("More blah blah");
cEgo.Say("Even more blah blah");
}

Right, so every Say command needs to be enclosed in own brackets?
I've probably made myself look a pillock. It's not the first time and it
certainly won't be the last.

Thanks for the replies.
Title: Re: DoOnceOnly
Post by: Atelier on Tue 28/06/2011 17:52:21

function code for walk on region.
{
      if(DoOnceOnly(" unique token "))
      {
            cEgo.Say(" Blah Blah Blah ");
            cEgo.Say("More blah blah");
            cEgo.Say("Even more blah blah");
      }
}


Here we go: if there's more than one statement after the if (here you have three), you need brackets around them. If it's just one, you don't need the brackets.

Also, it is just preference but indenting your code like this makes it much simpler for you to read.
Title: Re: DoOnceOnly
Post by: Matti on Tue 28/06/2011 17:55:27
It doesn't matter what commands you use, everything that happens depending on a condition needs to be within brackets, except it's just one single statement.


if (condition) Something happens



if (condition) {
  Something happens
  Another thing happens
  Yet another thing..
}


Edit: Yeah, what Atelier said.
Title: Re: DoOnceOnly
Post by: monkey0506 on Tue 28/06/2011 18:09:46
Just to be absolutely clear on this:

function region1_WalksOnto()
{
  if (Game.DoOnceOnly("unique token"))
  cEgo.Say("Blah Blah Blah");
  cEgo.Say("More blah blah");
  cEgo.Say("Even more blah blah");
}


Is exactly equivalent to:

function region1_WalksOnto()
{
  if (Game.DoOnceOnly("unique token"))
  {
    cEgo.Say("Blah Blah Blah");
  }
  cEgo.Say("More blah blah");
  cEgo.Say("Even more blah blah");
}


If you don't include braces after a conditional statement, then it is exactly the same as if you enclosed only the first statement after the conditional within braces. If you need more than one statement after a conditional statement to be run conditionally, then you must include all of those statements within braces yourself.
Title: Re: DoOnceOnly
Post by: Wizzard on Tue 28/06/2011 18:58:36
Too much previous exposure to BASIC programming isn't good for AGS scripting.
Thanks everybody for your helpful comments and examples.
I expect I'll be back with another idiotic posting in a week or two. :D