DoOnceOnly

Started by Wizzard, Mon 27/06/2011 23:08:13

Previous topic - Next topic

Wizzard

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?
Life is an adventure, but unfortunately you don't get restore points!!

Atelier

Could you post your code please?

Khris

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!?

monkey0506

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.

Wizzard

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.
Life is an adventure, but unfortunately you don't get restore points!!

Atelier

Code: ags

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.

Matti

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.

Code: ags

if (condition) Something happens


Code: ags

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


Edit: Yeah, what Atelier said.

monkey0506

Just to be absolutely clear on this:

Code: ags
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:

Code: ags
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.

Wizzard

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
Life is an adventure, but unfortunately you don't get restore points!!

SMF spam blocked by CleanTalk