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?
Could you post your code please?
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!?
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.
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.
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.
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.
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.
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