Timer doesn't expire

Started by TM, Thu 15/04/2010 16:20:48

Previous topic - Next topic

TM

Hi, I'm having difficulties with a timer. This is the setup:
After a mouse event in the inventory window, I start the timer:

Code: ags
function inventoryItem_Interact()
{
	SetTimer(1, 10);
}


then in repeatedly_execute, I check if it's expired:

Code: ags
function repeatedly_execute()
{
	if ((IsGamePaused() == 1) && (guiInventory.Visible == true))
	{
		if (IsTimerExpired(1) == true)
		{
			// do something
		}
		return;
	}
}


The timer seems to never expire, because "do something" never gets executed unless I set the timeout to 1 - then "do something" gets called immediately. Is it possible that the timer doesn't start to run when the game is paused or something weird like that? What's wrong here? Thank you for your help!

My website & blog

Khris

My guess is that a paused game also prevents Timers from ticking down.
In the case of the timeout being set to 1, the timer is apparently able to get to 0 before it stops ticking down.

Btw, a timeout of 10 is 0.25 seconds at the default game speed.

TM

Well, I think the timer expires when it reaches 1, since 0 is turned off. Also, the manual says that timers supposedly run on even when the game is paused. So I don't know. I'm confused.

My website & blog

Matti

I just checked the manual and didn't see anything about the timer ticking while the game is paused. So I guess there's your problem.

In case you really need to have a timer ticking while the game is paused, create a variable and increase it every game loop inside the repeatedly execute always function.

Gilbert

Unless the behaviour has been changed, the timers provided by the Timer functions in AGS should still be counting when the game is paused.

This actually caused a really hard to track bug in the beta versions of Pleurgburgh, as there were many timer puzzles in that game, so if you paused the game (say, bringing up the inventory screen, and this 'bringing up inventory screen' action was actually essential to solve some of these puzzles) during such puzzles and then the timer expires you'd be stuck and could not control the game thereafter.

That's why I personally avoid to use the timer functions and just use counter variables that are being decremented manually (in repeatedly_execute() or repeatedly_execute_always() depending on individual need) as they're under one's full control.

TM

Thanks for your replies. It says in the PauseGame entry:

"NOTE: When the game is paused, game cycles will continue to run but no animations or movement will be performed. Therefore, any timers that you are running or Wait() commands will continue to run as normal."

I've thougth about counting a variable, too. I will do that if this problem isn't resolved. I would just like to know why it doesn't work...

My website & blog

TM

After some further testing, I found out that indeed, timers are paused when the game is paused. At least in version 3.1.2. That's something that should be fixed in the help file.

My website & blog

SMF spam blocked by CleanTalk