How do you implement a Countdown clock?

CmdrWhitey13

  • Posts: 505
If going with the timestamp method, you may want to use global attributes to save the timestamp.

Create 1 global and have another local value.
Global should be implemented to save the current timestamp before closing the application.
Compare the global and local to get the difference to add life/energy accordinly.

Hope this helps.

thechaosengine

  • *
  • Posts: 329
Let's see if I can explain this properly. I have a system that gives the player a timed reward, Crossy Road style free gift after increasing intervals of time, eventually ramping up to every 6 hours. A lives system would be the same thing minus the increasing delay.

I have a game attribute called lastSavedTime.
I have a game attribute called resetTimer.
I have 3 local attributes: timeStart, timeCurrent, and timeEnd.

lastSavedTime is set to the 'get current timestamp' block from the Date extension, triggered whenever it's required (in a lives system, that would be when you lose a life).   

timeStart is set to lastSavedTime.
timeEnd is set to resetTimer.
timeCurrent is set to 'get current timestamp' every second, *if* [timeEnd + floor of [convert timeStart - timeCurrent milliseconds to seconds]>0]

when [timeEnd + floor of [convert timeStart - timeCurrent milliseconds to seconds] becomes <0, the required action is triggered to happen (in your case restock a life. Then either start over if the player has lost more lives, or just stop the whole process until another life is lost)

So basically what you're doing is setting a starting point as a number, an ending point as another number, you compare the difference until they become equal, and that triggers an action. Using game attributes for the start and end points is important because it means the game can function when the device is closed. what will happen when the game is opened again after 18 hours, timeStart is still set to 18 hours ago, timeCurrent is set to now, and since timeEnd is way lower than the difference of 18 hours, the action will be triggered. (note: and for a lives system you could add another calculation where if [timeEnd + floor of [convert timeStart - timeCurrent milliseconds to seconds] is 2,3,4x lower than timeEnd, replenish 2,3,4 lives instead of 1)

 

gecenab

  • Posts: 31
If going with the timestamp method, you may want to use global attributes to save the timestamp.

Create 1 global and have another local value.
Global should be implemented to save the current timestamp before closing the application.
Compare the global and local to get the difference to add life/energy accordinly.

Hope this helps.

Thanks for the tip... I'll try it!


Let's see if I can explain this properly. I have a system that gives the player a timed reward, Crossy Road style free gift after increasing intervals of time, eventually ramping up to every 6 hours. A lives system would be the same thing minus the increasing delay.

I have a game attribute called lastSavedTime.
I have a game attribute called resetTimer.
I have 3 local attributes: timeStart, timeCurrent, and timeEnd.

lastSavedTime is set to the 'get current timestamp' block from the Date extension, triggered whenever it's required (in a lives system, that would be when you lose a life).   

timeStart is set to lastSavedTime.
timeEnd is set to resetTimer.
timeCurrent is set to 'get current timestamp' every second, *if* [timeEnd + floor of [convert timeStart - timeCurrent milliseconds to seconds]>0]

when [timeEnd + floor of [convert timeStart - timeCurrent milliseconds to seconds] becomes <0, the required action is triggered to happen (in your case restock a life. Then either start over if the player has lost more lives, or just stop the whole process until another life is lost)

So basically what you're doing is setting a starting point as a number, an ending point as another number, you compare the difference until they become equal, and that triggers an action. Using game attributes for the start and end points is important because it means the game can function when the device is closed. what will happen when the game is opened again after 18 hours, timeStart is still set to 18 hours ago, timeCurrent is set to now, and since timeEnd is way lower than the difference of 18 hours, the action will be triggered. (note: and for a lives system you could add another calculation where if [timeEnd + floor of [convert timeStart - timeCurrent milliseconds to seconds] is 2,3,4x lower than timeEnd, replenish 2,3,4 lives instead of 1)

 

Ok... I think I'm getting a clear view of it... I'll try this as well
Thank you very much!

Btw... should all the attributes be numerical? I also got a doubt about the local attributes... My game consists of three scenes (a menu, an action and a game over scene), does it matter in what scene I place this local attributes?
 Or should this "life counter system" be placed on the start and retry button (which are the ones that decrements the life counter)

« Last Edit: August 23, 2017, 08:15:14 pm by gecenab »

thechaosengine

  • *
  • Posts: 329
Yeah all the attributes are numerical. You can swap the local attributes out for global ones if you'd like, but I don't think it matters because timeStart and timeEnd are set to global attributes and timeCurrent is always set to the difference between the other two. Now that I think about it, I suppose you could also just have 1 local attribute (timeCurrent) and use the global attributes (lastSavedTime and resetTimer) directly. I just set it up like this because I made it into a behaviour to use for multiple things if I want. 

I've attached the system to a button rather than a scene because i felt that it isn't actually necessary to always have it run; it only needs to compare the difference and trigger an action whenever relevant.

squeeb

  • Posts: 1617
its a scene behavior that you open up, and put in what you want to happen either daily, or weekly. or a short timer, for energy and what not.. Ceosol wrote it and commented on everything.. im not sure what we can do to make it more user friendly... heres a little sample of what to do... the heavy lifting is done with timerday, timershort ect in the scene behavior you can see listed in the event tab... i also have something similar i made that lets you do things based on time of day or day of week

<a href="http://static.stencyl.com/games/35930-0.swf" target="_blank" class="new_win">http://static.stencyl.com/games/35930-0.swf</a>

gecenab

  • Posts: 31
This is what I came up with... But every time i run it the game crashes.

Any ideas or tips?

thechaosengine

  • *
  • Posts: 329
maybe don't put everything in the same event, idk.