Idle Game Auto-Reset / GUI?

Started by harlana, Fri 01/09/2023 01:20:17

Previous topic - Next topic

harlana

Hi!

I am creating a short demo game to be displayed in a public gallery. I'm hoping to figure out a way for the game to automatically reset or display a "Are you still there?" pop-up after a certain amount of time idle, that way people can easily start from the beginning if someone walks away mid-game.

Is this possible? And what is the best way to do this? Sorry if this is a bit of a dumb question, this is my first AGS game and I am somewhat familiar with code but I'd still consider myself a beginner. I've read through the manual and found a lot of helpful information, but I'm not sure how to execute this or if it is even possible in AGS. Would love some guidance! Thanks :)

RootBound

#1
Absolutely possible and not too difficult.

First make the GUI for your idle question popup, and code the buttons there however you want. Then set the GUI visibility to false in the AGS editor.

Then put a timer in your global script (maybe under game_start, though there might be a better place depending on how you structured the game). Use SetTimer(), and set the timeout value as GetGameSpeed() times the number of seconds before the idle popup should appear.

Then, if you have a mouse based interface, under on_mouse_click, you set the same timer for the same amount of time, so that every time the user clicks, timer goes back to zero.

Finally, under repeatedly_execute, you check whether the timer is expired using an if statement with IsTimerExpired(). Put the code there to make the idle GUI appear.

Here's a link to the online manual and index. Just look up SetTimer, IsTimerExpired, GetGameSpeed, game_start, repeatedly_execute, and on_mouse_click for more detail. Hope that helps. :)

https://adventuregamestudio.github.io/ags-manual/genindex.html

(If I have made any mistakes here, more advanced users please feel free to correct me).
J. They/them. Here are my most recent games:

Crimson Wizard

I must clarify: there are two ways to count time in AGS.

First is using Timers. Timer counts game ticks, and depends on a game speed setting. Timers are considered to be a part of the game state, so their values may change when a game save is restored, for instance. They are also paused when the game is suspended, like when player alt+tabs from the game window.
For this reason they are best used for the in-game events.

Then, there's a DateTime struct which lets you use system time, when you need a "real" time, which does not depend on game speed or in-game events.
https://adventuregamestudio.github.io/ags-manual/DateTime.html

SMF spam blocked by CleanTalk