The Daily Click ::. Forums ::. Klik Coding Help ::. Total Time Played / Saving & Loading
 

Post Reply  Post Oekaki 
 

Posted By Message

HaZe



Registered
  28/08/2011
Points
  11
28th August, 2011 at 13:09:09 -

Hi guys!
I'm working on a virtual pet game, and i'm curious about the saving and loading of game data, specifically the total amount of time played. So far I've established a few variables, (hunger, happiness, etc.) and I am using the Store X extension to save and load these values, and it works great. My problem arises when i'm trying to create a global timer that I can use to control certain events along the creatures life. I'm working with the Time X extension at the moment, and it counts in milliseconds. I would have no problem storing that value in my save file, and retrieving it later, but its very impractical to try to measure everything in milliseconds. So my question is this:

Is there a better way to go about saving and loading total time played?, if so where can I learn about it?

This is kinda the backbone of the project, so I would like to make it as efficient as possible, since almost every aspect of my game will be dictated by this global clock. Thanks in advance!



 
n/a

HaZe



Registered
  28/08/2011
Points
  11
28th August, 2011 at 14:14:32 -

Okay, I believe I have it working now, here's what I did:

I created three counters, one each for hours, minutes, seconds. Then I retrieved the elapsed time (in ms) and made the proper unit conversions, and applied a mod function to the result, which basically tells the counter reset to 0 at a certain value, and did that for each of my three counters, As for saving and loading, I just used the actual time in ms, and I'll just reference the counters when I need to check how many minutes or hours have elapsed. Here is the math functions I used for those who are interested where A is the time in milliseconds:

seconds=(A/1000)%60
minutes=(A/(1000*60))%60
hours=(A/(1000*60*60))%24

Hope this helps someone in the future!



 
n/a
   

Post Reply



 



Advertisement

Worth A Click