In my game, picking a dialog option causes a string of events.
I currently have the if statement in the room's repeatedly execute function.
This is problematic, because once the dialog option is chosen, it repeats the event forever.
Here is my code.
function room_RepExec()
{
if (ddanger.HasOptionBeenChosen(1)){
ddanger.SetOptionState(2, eOptionOn);
ddanger.SetOptionState(3, eOptionOn);
}
if (ddanger.HasOptionBeenChosen(3)){
cego.Walk(45, 60, eBlock, eAnywhere);
}
}
How can I solve this problem? Thank you!
Maybe you could set a bool to skip the routine once it's been done?
One of the builin methods to ensure that some action takes place only once in AGS is Game.DoOnceOnly:
if (ddanger.HasOptionBeenChosen(3) && Game.DoOnceOnly("DangerOption3Chosen")){
(the string you pass to DoOnceOnly is arbitrary, but unique to identify particular case)
I may be totally off base but if you really just want it to run once during the whole game then Crimson Wizard's would work great since that is what DoOnceOnly was created for, but why are you doing this code in the RepExec function.
How about in the dialog code for option 1 you turn on option 2 and 3, and the dialog code for option 3 you put your walk command.
Like everyone says, it would be better to use DoOnceOnly. But if for whatever reason you want to use RepExec, here's the code I would use.
function room_RepExec()
{
if (ddanger.HasOptionBeenChosen == 1){
ddanger.SetOptionState(2, eOptionOn);
ddanger.SetOptionState(3, eOptionOn);
ddanger.HasOptionBeenChosen = 0;
}
if (ddanger.HasOptionBeenChosen == 3){
cego.Walk(45, 60, eBlock, eAnywhere);
ddanger.HasOptionBeenChosen = 0;
}
}
Quote from: Danvzare on Fri 17/06/2016 09:56:03
Like everyone says, it would be better to use DoOnceOnly. But if for whatever reason you want to use RepExec, here's the code I would use.
Danvzare, your code won't even compile... HasOptionBeenChosen is a function, and you are using it as a variable.
Quote from: Crimson Wizard on Fri 17/06/2016 10:05:22
Quote from: Danvzare on Fri 17/06/2016 09:56:03
Like everyone says, it would be better to use DoOnceOnly. But if for whatever reason you want to use RepExec, here's the code I would use.
Danvzare, your code won't even compile... HasOptionBeenChosen is a function, and you are using it as a variable.
Doh. I did a dumb thing. :-[
Thanks for the correction.
Here's the standard way, like dayowlron suggested:
// dialog script
...
@1
...
option-on 2
option-on 3
return
@2
...
@3
...
cego.Walk(45, 60, eBlock, eAnywhere);
...
return
(Note that the .Walk() command is indented, while option-on X and return are standard dialog commands that mustn't be indented.)