How do I create an Energy System that works even if the Player is connected or not?

0 favourites
  • 7 posts
From the Asset Store
Basic Rounded Vector Geometry Player Design with Glow for 3 player games
  • Hi everyone,

    Do you know how to implement several countdowns that continue working even if the Player is not connected?

    I'm close to finish the game I'm working on and now, I start working on the backend, something where I have no experience with as a developer.

    Do you have some processes / steps to share to help me figure how to implement this timer system?

    I found on the forum that some of you suggest using Rex plugin Date & time.

    I did not try it yet but I wanted to know if it is possible to do it without using an external plugin?

    If you have some links, tutorials, ideas to share.

    Thank you everyone

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • try getting a timestamp from the system each time you start the game, then calculate how much time has passed from there.

    The game will not be "running in the background" you only need to make it seem like it is..

  • Thanks Jobel.

    The idea is interesting.

    Not sure it is what I'm looking for but I'll think about it.

  • Browser.ExecJS("") will give you the number of milliseconds between 1/1/1970 and now. You can put that number into local storage whenever you wish. When the user starts the game the next time, you can get that number again and subtract the stored value from the current value and know exactly how many milliseconds has elapsed since you stored that number.

    Browser.ExecJS("") - stored value = milliseconds elapsed.

    One thing to take note of. Storing variables in local storage is not secure in any way. It's entirely possible, and not that difficult, for a user to go in and edit those variables manually.

  • Thank you both of you.

    Yesterday, I tried Jobel's idea and it's kind of working.

    Fengist Thanks Fengist, it's indeed an easier way to achieve what I have done yesterday.

    I will correct what I've done.

    However, you brought a good point, in the 2 cases, it's not really secure.

    Is there a more secure way than local storage for Construct 2?

  • Not really. You could try to encrypt the local variable and that would deter most people. The problem there is, any password you use to encrypt and decrypt it would be located somewhere in the code. Anyone dedicated enough would eventually find a way to decrypt it. (Trust me, I've had keygens made for software I've written).

    I'm doing something very similar to what you are. I have skills that require x amount of time before they can be trained. What I do is send an AJAX request to a PHP file when they choose a skill to train. When it gets that request it stores that timestamp in a MySQL database. When the user logs in, it sends an AJAX request to retrieve that timestamp. It compares it to the current timestamp and if enough time has elapsed, it sends another AJAX request to update their skills. If the time hasn't elapsed, I have a 1 sec timer on a global event sheet that keeps checking to see if that time has elapsed.

    But, you even have to take other things into account. What if they change the clock on their computer to be say, a week in the future? You'd need some way to validate the current time.

    If people want to hack your game, they will. All you can do is make it as difficult as possible. My solution isn't perfect but, storing things like that remotely on a server is about the best you can hope for.

  • Thanks again for your time and advice.

    I'm more worry for the security of the users.

    Nothing is secured proof but if the users are safe, I'm fine :)

    You right when you say "All you can do is make it as difficult as possible."

    Great example, it's exactly what I was thinking, using the server time.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)