How to count time between game sessions?

0 favourites
  • 3 posts
From the Asset Store
Be quick and count the cards and choose the right number!
  • Hello everyone,

    For my game I am trying to create a system that count gameplay time and if the player plays more than lets say 4 hours then negative buffs will be applied until he rests.

    Resting time will be valid only if the player in not playing. So for example if i set 8 hours until full rest, the game needs to know that if the player comes back after 8 hours, the negative buffs will be removed.

    In case its helps, the idea behind all this is to create some kind of anti-addiction system in games.The game will be offline only.

    It would be greatly appreciated if someone could explain or point to a direction on how to be able to count the time between the game sessions so i know the player actually did not play for at least 8 hours.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I'd use a combination of onSuspended condition and Unix time (https://en.wikipedia.org/wiki/Unix_time).

    You'd simply record the Unix timestamp when the user closes the game (onSuspended), and then subtract this number from the Unix stamp when the game is opened again - if the number is greater than 28,800,000 (8 hours in milliseconds), then you know that 8 hours or more have passed.

    The one thing I'm not sure on is if onSuspended is called if the app is closed rather than suspended

  • I suggest to use this third party plugin:

    c2rexplugins.weebly.com/rex_date.html

    (download on the top left link on the page)

    Then you go like:

    On Start of Layout
     Set [Global Text Variable] to (Date.Year & "/" & Date.Date & "/" & Date.Day & "/" & Date.Hours & "/" &Date.Minutes)
    

    Then you need to put this into the localstorage / webstorage and restore the date upon a new game session from there and compare.

    It's pretty tricky to do for a beginner, I suppose, but this way, it will work.

    Edit: Or maybe you want to store year, date, day, hours and minutes into different variables for easier handling. I believe that may be easier.

    Edit: The plugin appearently also supports Date.Date2UnixTimestamp.

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