Running a timer inside dialog, having dialog stop when it's expired

Started by gabfratr, Sat 18/01/2025 19:07:34

Previous topic - Next topic

gabfratr

Hi!
I'm attempting to have a dialog end on its own after a given amount of time has passed. However, starting the timer and checking if it's run out with AGS script inside the dialog won't work; as far as I understand, I need to put that in a repeatedly_execute_always function. I set the timer on the room_Load function, and put checking for/resetting on the repeatedly_execute_always function, with a dummy Say command from a character, but the timer only runs when the dialog isn't open.


I've been searching other threads for this issue, and messing with CurrentDialog and StopDialog(), but I couldn't really understand the context of the answers to similar questions. Also read someone suggesting using the Custom Dialog options, but checking the manual I feel that's too advanced for me at this point.

Thanks in advance.

Crimson Wizard

Please clarify your intent, do you want to abort a dialog when dialog options are displayed, or in virtually any point of a dialog script (like, in the midst of characters talking, etc)?

gabfratr

Quote from: Crimson Wizard on Sat 18/01/2025 20:47:02Please clarify your intent, do you want to abort a dialog when dialog options are displayed, or in virtually any point of a dialog script (like, in the midst of characters talking, etc)?

Ideally, when dialog options are displayed: I'd like to implement a way for the dialog to shut itself if the player takes too long to choose any option. As if the NPC got bored and wandered off (I suppose the next logical step would be to reset the timer any time the player returns to the option tree and takes too long to pick another dialog option, but that sounds even more complicated, I'd be okay with it just working once, before any option is chosen).
I crammed the whole thing (setting the timer, running it and resetting) into the room script where the character with the dialog is. The timer does work, as the SayBackground test pops up every few seconds. Couldn't understand the use of CurrentDialog and StopDialog via manual though, and the obviously incorrect "if" statement triggers an error.

Code: ags
function repeatedly_execute_always(){
 
// Error (line 10): '.CurrentDialog' is not a public member of 'Dialog'
 if(Dialog.CurrentDialog == dDialogoCuchara){
 if(IsTimerExpired(1)){
   //dummy dialogue
   cCuchara.SayBackground("Me aburro.");
   SetTimer(1, 120);
}
}
}
function room_Load()
{
  SetTimer(1, 120);
}

Crimson Wizard

First of all, you have to make sure that "Run game loops while dialog options are displayed" is enabled in General Settings.

Then, Dialog.CurrentDialog is introduced in v3.6.2, this is mentioned in "Compatibility" note in its article.
StopDialog may also be working differently in older versions.
Which version of AGS are you using currently? Depending on version you may need to use different solution.




gabfratr

I actually enabled that option and then disabled it because I figured it wasn't relevant to my issue  :grin:

Well, I feel silly now, I'm running v3.6.1. Is there any way to work around it, or should I go ahead and download 3.6.2?

Crimson Wizard

In regards to StopDialog, appears it does not work when called from anything that was not run directly from dialog script. Meaning it does not work from rep-exec-always either. I think that's a mistake, and I will try fixing this in 3.6.2.

There may be ways to achieve this in 3.6.1 too, perhaps more than one.

The dumb way is to use "custom dialog options" API, which lets you manually control how dialog options are run. It may be possible to have a hidden dialog option that just exits the dialog, and run that option from "dialog_options_repexec".
The problem with this way is that "custom dialog options" require you to script options drawing and selecting as well (you can't replace only part of behavior). If you go this way, you may use some default implementation, shown in examples.

But maybe there are other easier ways.

Rik_Vargard

Would it be complicated to have a dDialog.Stop(); that would just close the gui ?

Crimson Wizard

Quote from: Rik_Vargard on Sun 19/01/2025 10:12:28Would it be complicated to have a dDialog.Stop(); that would just close the gui ?

There is already a StopDialog function that is supposed to stop a dialog, but it was working only in very specific case in the previous versions.

SMF spam blocked by CleanTalk