• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML Coding with real time

L

logan12v

Guest
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.
 

Cat

Member
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!
 
B

Bayesian

Guest
From there, it's just a matter of simple subtraction to find out how much time has passed.
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
 
L

logan12v

Guest
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
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?
 

NeoShade

Member
@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
 
L

logan12v

Guest
@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
Thx this is vary helpful I did not see that function I must have over looked;)
 
Top