GML Coding with real time

Discussion in 'Programming' started by logan12v, Sep 6, 2018.

  1. logan12v

    logan12v Member

    Joined:
    Nov 18, 2017
    Posts:
    65
    I have a game I am making and I want to use real time. I have used date_time_string and date_date_string. I have the current time stored in the variables Time and Date but I don't know were to go from here. I want to make it were I can write a code that can figure how many days have passed from when an event has happened. like when you first load the game lets say you dident play for 3 days when you come back in the game It knows you did not get on the game for 3 days now your dead and have to start over?

    Any knowledge with time code would help if you know how to code something likes this it would be a lot of help if you could post it. Thank you for all the help.
     
  2. Cat

    Cat Member

    Joined:
    Jun 22, 2016
    Posts:
    68
    First off, you're going to need to know when the game was last played. To do that, you'll need to implement saving and loading. If I recall correctly, GameMaker: Studio should have a built-in tutorial on this. Alternately, Shaun Spalding has a predictably excellent tutorial as well.

    You now have both the time/date that the game was last played as well as the current time/date. From there, it's just a matter of simple subtraction to find out how much time has passed.

    Good luck on your game!
     
    logan12v likes this.
  3. logan12v

    logan12v Member

    Joined:
    Nov 18, 2017
    Posts:
    65
    Thx
     
    Last edited: Sep 6, 2018
  4. Bayesian

    Bayesian Member

    Joined:
    Sep 13, 2016
    Posts:
    421
    GMS doesn't know how many days are in a month to roll over your math, he's going to need a library extension to do calendar math
     
  5. logan12v

    logan12v Member

    Joined:
    Nov 18, 2017
    Posts:
    65
    Is there a way you can show me how to do this?
     
  6. logan12v

    logan12v Member

    Joined:
    Nov 18, 2017
    Posts:
    65
    Why can't I use date_create_datetime when new game starts then every time game is loaded after that use date_compare_datetime to see if 3 days have passed or do these functions not work like that?
     
  7. NeoShade

    NeoShade Member

    Joined:
    Jun 21, 2016
    Posts:
    166
    @Bayesian : GMS2 is actually perfectly capable of counting time like this.

    date_day_span will give you the number of days between two dates, so you can use date_current_datetime when you save the game, and again when you load the game, then use date_day_span to count how many days since you last played.
    There's heaps of very useful date and time functions that pretty easy to work with. https://docs.yoyogames.com/source/dadiospice/002_reference/date and time/index.html
     
    Bayesian, IndianaBones and logan12v like this.
  8. logan12v

    logan12v Member

    Joined:
    Nov 18, 2017
    Posts:
    65
    Thx this is vary helpful I did not see that function I must have over looked;)
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice