GameMaker [HELP] - Energy System (mobile games)

GDK

Member
I'm looking at potentially adding some type of "Energy System" to my game OR features/mechanics that are linked to "real-time" cool downs much like how buildings/upgrades work in Clash of Clans.

So I'm guessing there will need to be some sort of server-side / networking element to it. If so...
1. Is it relatively complex to implement?
2. How should I go about setting it all up?

**I have no idea what it involves, so please ask me questions if my request is too vague or point me in the right direction**
 

Yal

🐧 *penguin noises*
GMC Elder
There's a lot of functions that get the current time from the OS:
https://docs.yoyogames.com/source/dadiospice/002_reference/date and time/index.html

For instance, current_second is a read-only variable that contains the current second since the Unix Epoch(?). It doesn't matter what it measures from, it's a number that goes up once per second.

So... to get a real-time cooldown on an action: store the timestamp it was initiated. Regularly, check the current time. If any event is as long in the past as its real-time cooldown, the cooldown ends. So for energy, you'd store the "last time you got an energy" timestamp, and whenever the current time exceeds this time with [as much real time you want between refills], add an energy unit and update the "last energy time" timestamp.

This should also be persistent between reboots, so you can store these to a file when the game ends, and upon load, add as much energy as the player is entitled to depending on time difference (and adjust the stored times accordingly).


Now, this all sounds super simple, right? What you need to be aware of is that the player can trick this system by changing their OS time. So it's not as foolproof as a system using a server. But if you can live with that (and assuming most players won't realize this), it's pretty straightforward to implement.
 
  • Like
Reactions: GDK
C

Carcophan

Guest
Now, this all sounds super simple, right? What you need to be aware of is that the player can trick this system by changing their OS time. So it's not as foolproof as a system using a server. But if you can live with that (and assuming most players won't realize this), it's pretty straightforward to implement.
Say we did have access to a server, would it be the same principal, just using the servers OS time, versus the devices? Since the user will not be able to change the servers TS?
 

GDK

Member
@Yal Thanks, Ill take a look at those docs and see how I go. Definitely gives me something to go ahead with but Ill be coming back here if I strike any issues :p
 

Yal

🐧 *penguin noises*
GMC Elder
Say we did have access to a server, would it be the same principal, just using the servers OS time, versus the devices? Since the user will not be able to change the servers TS?
Good point! Come to think of it, there probably is a bunch of services that give you the current UTC timestamp if you query them - a lot of modern OSes synchronize their time with a server somewhere and there's probably at least one free alternative.
 
Top