Panga97
Panga97

Reputation: 81

Display current time Game Maker

I've been trying hard to simply display the current time and couldn't find a solution anywhere...so sorry for the misplaced post.

All I want is to display the time on the user's pc or phone.

What I can do is get the time to show up in a box message but not have it just displayed and updated every second.

This is my current code

//store the current time
t=date_current_datetime();

//get the hour portion of that time
h=date_get_hour(t);

//get the minute portion of the time.
m=date_get_minute(t);

//get the second potion of the time
s=date_get_second(t);

//show the time
txt="The current time is:"+string(h)+":"+string(m)+":"+string(s);
show_message(txt); 

Hope this gamemaker code makes sense, thanks for any help.

Upvotes: 3

Views: 2667

Answers (1)

Dmi7ry
Dmi7ry

Reputation: 1777

Ok, add to Create event:

txt = "";
alarm[0] = 1;

Move your code to Alarm 0 event:

//store the current time
t = date_current_datetime();

//get the hour portion of that time
h = date_get_hour(t);

//get the minute portion of the time.
m = date_get_minute(t);

//get the second potion of the time
s = date_get_second(t);

//show the time
txt = "The current time is: " + string(h) + ":" + string(m) + ":" + string(s);

alarm[0] = room_speed;

And last - Draw event:

draw_text(10, 10, txt);

Of course also you can use Draw GUI event or view coords, like

draw_text(view_xview[0] + 10, view_yview[0] + 10, txt);

Upvotes: 6

Related Questions