Jump to content

Exiting/ resuming cartridges and timers


murphley

Recommended Posts

I've read in another topic from a few years ago that if you set a countdown timer and exit the cartridge it will continue to run, and once you go back in whatever you set up to happen when tick time event occurs will not trigger. Is this correct?

Edited by murphley
Link to comment

You have the right idea, but the details are incorrect. Timers do not continue to run after a cartridge has been exited. Nothing runs after exiting a cartridge. However, when a cartridge is restored, the player app should call the tick events of any previously-running timers.

Is there any way to work around this behaviour? In some of my cartridges I'd like the timer to stop on exit and re-start from the same point when the cartridge is started again (or at least behave as if this is what was happening) without the tick events being called immediately on re-start.

Link to comment

Yes, you can work around this.

 

Short Answer:

Use two variables to keep track of the time remaining and if the timer was active. Use one timer to tick off the time remaining value. When the cartridge is resumed, check the timer active variable and, if the timer was active, start it again.

 

Long Answer:

Define a variable equal to the number of seconds in your timer. For example, let's say your timer is sixty seconds. That variable's value will be sixty. Please note this variable's value must be saved with the cartridge. If you create the variable through a builder application, that satisfies the condition. If you're hand-coding, the variable must be saved with Wherigo's variable collection object. I'm going to refer to this as the time remaining variable.

 

Next, define one other variable. You can make it a Boolean (flag), number, text, or whatever. The point of this variable is to indicate whether your timer is active. You can use true and false, zero and one, T or F, etc. This variable must also be saved with the cartridge. Make sure its initial value is false. I'm going to refer to this as the timer active variable.

 

Next, define a three second timer (because I'm trying not to be as resource intensive). When you start the timer, set the time remaining variable equal to however long you want to time. Also set the timer active variable to true. When the timer ticks, subtract the interval time from the time remaining and test that the value is not less than or equal to zero. If the time remaining is still positive and non-zero, start the timer again. If not, perform whatever action you would have done if the user ran out of time. I'm not suggesting you use an interval timer here because I thought some of the Garmin players at one point had an issue with stopping the interval timer.

 

I hope you follow me so far. Now, when the cartridge is resumed, check the value of your timer active variable. If the value is true, you know the cartridge was exited while the timer was running. You have the last known value of the timer within your time remaining variable. Since you're counting off time using the time remaining variable, everything is already set up for you. Simply start your timer and your cartridge will be as if the user had never exited it.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...