time based couters

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Wulfie
Prole
Posts: 12
Joined: Mon Apr 11, 2011 6:46 pm

time based couters

Post by Wulfie »

Hello folks.

I have finally sorted out what my first project will be. Now I'm stuck lol. A huge portion of my game will depend on the amount of time that has passed.

An example of what I am trying to do;

Say I want to simulate the discharging of a battery.

Start
BatteryCharge = 100 (static # or percentage, either would work)
**a mix of percentage drain on a static # would be ideal.
After one hour of Real World Time the Battery Charge would = 80 (again static # or percentage would work)

The math basics I get what I'm stuck on is 2 things.

How do I pull current time and build a counter around that ?

How can I make it so that if you close the game all together and come back an hour later and load it, an hour has still passed and the battery is still drained by 20% / 20 points ??

Any assistance with how to code this and or how to get time and count from it both during play and offline time, would be greatly appreciated. As i stated this is a big part of my game idea. The HUD/GUI 2d tile grid etc etc I can handle in lua.

Thank you again for your feedback / assistance
"We do not stop playing because we grow old. We grow old because we stop playing." -- Unknown
User avatar
nevon
Commander of the Circuloids
Posts: 938
Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:

Re: time based couters

Post by nevon »

Use os.time to get the current timestamp. Save that timestamp along with your charge and whatever else you need to save, in the love.quit callback. Then when the game is loaded again, the elapsed time is os.time()-oldTimestamp.
User avatar
Wulfie
Prole
Posts: 12
Joined: Mon Apr 11, 2011 6:46 pm

Re: time based couters

Post by Wulfie »

Awesomesauce thank you so much for the quick and informative response. I appreciate it.

for some reason I could not get time::gettime out of my head.. lol
"We do not stop playing because we grow old. We grow old because we stop playing." -- Unknown
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: time based couters

Post by BlackBulletIV »

By the sounds of it, a tweening library would help. EmmanuelOga's tweener library might do the trick.
User avatar
nevon
Commander of the Circuloids
Posts: 938
Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:

Re: time based couters

Post by nevon »

BlackBulletIV wrote:By the sounds of it, a tweening library would help. EmmanuelOga's tweener library might do the trick.
Whut? How do you figure that?
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: time based couters

Post by BlackBulletIV »

Wulfie wrote:How can I make it so that if you close the game all together and come back an hour later and load it, an hour has still passed and the battery is still drained by 20% / 20 points ??
Argh, I didn't read that.

From what I skimmed I originally thought that Wulfie wanted a timer that wasn't lasting, which a tween can pull off fine (although the practicality of an hour tween I don't know).
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 49 guests