Clock countdown to specific date V2
0belisk
PRO Posts: 189
This is a repost of my previous thread in the PRO - Working with Gamesalad section, so if reposting this is against the rules please feel free to delete this.
The reason for this is because i havent received a response in the PRO forums for 4 days and therefore have now come to the normal forums to try here!
lets get to it:
Ive researched and dug up some old posts regarding this same topic before here on the forums, but I'm still very puzzled how to approach this.
I know you need to make a set of attributes for the target month, day and time, then use the device's clock to determine the difference to display the appropriate countdown, but as for the maths side of it, im truly puzzled.
Has anyone else done this before? Or has any insight how to implement such a feature, i have the OSTime demo template, and a countdown template that I've analysed, but none of these have any information/mechanics for counting down to a specific date.
Ive used countdowns before, but with pre-inputted variables, obviously this is very different as everytime the application is opened it needs to recalculate the countdown.
plan on displaying the countdown in the format of: Days - Hours - Minutes, but if its easier to do it an alternative way i have no problem with changing the format.
Thanks in advance
The reason for this is because i havent received a response in the PRO forums for 4 days and therefore have now come to the normal forums to try here!
lets get to it:
Ive researched and dug up some old posts regarding this same topic before here on the forums, but I'm still very puzzled how to approach this.
I know you need to make a set of attributes for the target month, day and time, then use the device's clock to determine the difference to display the appropriate countdown, but as for the maths side of it, im truly puzzled.
Has anyone else done this before? Or has any insight how to implement such a feature, i have the OSTime demo template, and a countdown template that I've analysed, but none of these have any information/mechanics for counting down to a specific date.
Ive used countdowns before, but with pre-inputted variables, obviously this is very different as everytime the application is opened it needs to recalculate the countdown.
plan on displaying the countdown in the format of: Days - Hours - Minutes, but if its easier to do it an alternative way i have no problem with changing the format.
Thanks in advance
Comments
You could use the equations in this example as a basis for a day counting app.
http://www.mediafire.com/download.php?uuafy6nbvl050jk
Thank you very much! After briefly analysing that project i just changed the "Start day" "Start month" and "Start year" variables to the device's day, month and year and it is appearing to display the correct days until the specified date.
Now i just need to workout displaying the hours and minutes until the date, which im thinking i will just display the device's time, in reverse fashion, so if its 16:00pm, instead of displaying 16:00, it would display 08:00 to represent how many hours are left in the day.
And i would assume ill do the same for the minutes, and potentially even seconds.
Ill keep this updated how i get on!
@Obelisk -- You are welcome. Once you get to thinking about it, you will probably see that its overkill for short term countdowns. But if you ever want to know how many days until your 50th Christmas -- this equation ought to do it for you!
Be careful about counting down days into the future! For example, if you use this to count how many days until Christmas, it will tell you there are 14 days. But remember that today (in the middle of the US) there are 13 days and about 10 hours left to go. (But who is counting such things?!?)
And in the application description on the Appstore ill emphasise to ensure you have the correct date/time on your device for some of the apps functionality to work correctly.
I was referring to the way the equations would count today (a partial day) as a full day when its counting down to a future date. So, even though there are 13 days and about 10 hours until Christmas, the equations will give 14 days.
Its a case of the famous 'off by one' bug that creeps into coding all the time.
To fix this, which i havent fully investigated is a definite solution yet, i just changed the equation for the calculated quantity of days to "target day-start day-1" and it is now displaying correctly lust far.
And i will add a rule later to ensure when it is the actual day of the countdown, it wont have a value of -1 instead of 0, ill make a rule "if the quantity of days left is equal or higher than 1."
And as for the hours, firstly to reverse it incase anyone was wondering inside the equation of the number actors to display the correct number image relative to the number value (as seen in the OSTime demo), i just changed it from:
Hour digit 1
(floor((game.Clock.Hour %24)/10))..".png"
to
(floor((23- game.Clock.Hour %24)/10))..".png"
Hour digit 2
(game.Clock.Hour %24%10)..".png"
to
((23- game.Clock.Hour %24)%10)..".png"
This reversed the display game.clock.time into a countdown fashion, so 16:00pm displays as 08:00, showing the time left of the day. And using the figure of 23 hours instead of 24, accounts for again what you mentioned about the "one day behind bug", which is also relevant for hours to it would appear. I also changed the %24 in the equation from its original value of %12 to change the format of the hours from a 12 hour clock to a 24 hour one.
-1.5 + ((Game.Clock.Year -2011) * 365 * 24 + floor ((game.Clock.Month -1) * 30.5) * 24 * 60 + (game.Clock.Day -1) * 24 * 60 game.Clock.Hour * 60 + + + game.Clock.Second game.Clock.Minute / 60)
not understand that should change to suit a custom time for me, for instance if I want to happen every 30 minutes? etc
then let me another question if you please, I would like to know how I can create a countdown in hours, minutes and seconds, I would like to be saved each time you exit the game and continue once you have entered the game, thank you very much for your help. You are very good
Hour digit 1 actor
constrain self.image to: (floor((23- game.Clock.Hour %24)/10))..".png"
Hour digit 2 actor
constrain self.image to: ((23- game.Clock.Hour %24)%10)..".png"
To defuse any confusion, if the time was 23:00, hour digit 1 is "2" and hour digit 2 is "3".
And the reason for the 23 in the equation instead of 24 (hours in a day), is so for example it doesnt display 01 hours left, if the device's time was 23:15, as really its 00 hours and 45 minutes, not 1 hour and 45 minutes.
And you do a similar thing for the minutes:
Minute digit 1 actor
constrain self.image to: (floor((60- game.Clock.Minute )/10))..".png"
Minute digit 2 actor
constrain self.image to: ((60- game.Clock.Minute )%10)..".png"
And for seconds i would imagine you just literally do the same as ive done for the minutes just with game.clock.seconds obviously, i havent tried it myself but i see no reason for it not to work as they both go up to 60.
This will reverse the display of the game.clock.time so it counts down not up as it would normally. If you want to do a countdown with a preset given variable and not the device's clock, you can adjust the equation removing the game.clock and inserting a self.attribute or global attribute with the time you desire i guess, and remove the numbers I've included before the game.clock as i dont think you would need them.
As for saving the time when the user quits the game so you can later resume the countdown, make some global integer attributes, "countdown hour" "countdown minutes" and countdown "seconds" make a rule which would trigger when the user exits: that will save the the individual parts of your countdown, to the countdown attributes you've made, and when you go back into the game, load the saved attribute values back into the countdown.
Example:
(using game.clock for instance not pre-set variable)
Rule
- Insert trigger here - (user quitting)
Change attribute "countdown hours" to "23- game.Clock.Hour"
save attribute
countdown hours
do the same for minutes and seconds, then in the scene with your countdown, have it at the start, load these attributes back up, which the countdown equations use to calculate the countdown, and it will adjust it back to where it left off.
Building a countdown clock to a specific date and cant get my head around the math of it! who else to turn to but you
Much appriciated
OK -- I think I found the project you are referring to. I put it into the "spare code" thread.
http://forums.gamesalad.com/discussion/comment/414285/#Comment_414285