How do I measure time away from game?

  • Okay, I've thought I had this figured out before but nothing seems to correctly measure the time away (time where game is not playing versus time game is playing) for an "idle" feature I want to include in a game I am building.

    The idea: I want players to gain Turns and regen Health when the game is not running.

    The best I can come up with: Find a way to record the current time recorded as a global variable before game is saved (using the Unix epoch measure of time in ticks) and subtract that from the current time which is recorded as a global variable (using same measure of time) when a player logs in and loads the saved game. From there it would just be a matter of dividing the remained by the ratio I want to increase Turns and Health by.

    The problem: I can't for the life of me find the correct way to pull the measure of time (Unix epoch measure in ticks) and I am not sure that is the best way to do it.

    I want to avoid adding another plug-in to my game, so I'm hoping for a native way to do this.

    Any thoughts?

  • Okay, I figured it out.

    Ended up using RexRainbow's Date plug-in and creating an event to save the Unix Timestamp to a GV before saving the game. Then when a saved game loads it records the Unix Timestamp. From there the timestamps are compared, difference is divided and the Turn and Health ratio is used to increase those GVs.

    So far it seems to work perfectly.

    A note to anyone trying this; compare the variables in a place where the saved game will launch (ie; not right after the game loads but on an event sheet that was used when the game was saved).

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Yep that would've been my response, gets asked a bunch on here ^^

  • For reference, you can do this without plugins via browser execjs expression: Browser.ExecJS("Date.now()")

    Also Construct 3 has the new "unixtime" system expression

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