Ideal Game Help

Roavid

Member
Hi i am currently making a ideal game and I was how I would go about making so it kept track of what you were earning when the game was closed. Many thanks I'm advance
 

TsukaYuriko

šŸŒ 
Forum Staff
Moderator
I'll assume that you meant "idle game".

The basics go roughly like this: When exiting the game, save the time it was closed at. You can use current_time to get the current time.
When opening it again, calculate the difference between the time now and the time when it was closed.
Use that with a formula that provides you with the average gain during that time period. For example, if you gain 5 gold for every second while the game is closed and had it closed for 60 seconds, you'd gain 5 * 60 = 300 gold.
 

Roavid

Member
Yes thank you this is exactly what I needed. I had no idea that function existed I was planning on using a server to track when the player logs in and logs out and having their score attached to a player ID. But this is perfect. Thank you
 

ophelius

Member
You may also want to save and retrieve your data with base64_encode and base64_decode in order for people to not tamper with the time codes to cheat, it'll make sure the file is scrambled when looking at it from a text editor:

 

Yal

šŸ§ *penguin noises*
GMC Elder
When exiting the game, save the time it was closed at. You can use current_time to get the current time.
It might be a good idea to save the time every 5-15 minutes or so even if the player doesn't close the game. If they force quit the game (or it crashes, or they have a power outage), the time normally wouldn't be saved on-quit. This could make them lose progress... or gain too much progress, since it now will look like they haven't played the game since the PREVIOUS time they played it.
 

Roavid

Member
Thank you for your support guys the answers submitted have really helped and i appreciate it. :) and yes i did mean Idle lol.
 
Top