Advertisement
Lmeagno

[GML] Basic Clock Timer Display

Apr 14th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. //Countdown seconds by delta_time's microseconds
  2. totalSeconds -= (delta_time/1000000);
  3.  
  4. var t,years,days,hours,minutes,seconds,timerDisplay;
  5.  
  6. //Integer Math
  7. t = (60*60*24*365); years = (totalSeconds div t); //Does not handle leap years
  8. t = (60*60*24); days = (totalSeconds div t) % 365;
  9. t = (60*60); hours = (totalSeconds div t) % 24;
  10. t = (60); minutes = (totalSeconds div t) % 60;
  11. t = (1); seconds = (totalSeconds div t) % 60;
  12.  
  13. //Convert Integers to String Values
  14. years = string(years);
  15. days = string(days);
  16. if (hours < 10) hours = "0"+string(hours); //If timer value is less than 10
  17. else hours = string(hours); // add "0" for two-digit counter
  18. if (minutes < 10) minutes = "0"+string(minutes);
  19. else minutes = string(minutes);
  20. if (seconds < 10) seconds = "0"+string(seconds);
  21. else seconds = string(seconds);
  22.  
  23. timerDisplay = years + "years / " +
  24. days + "days\n" +
  25. hours + ":" + minutes + ":" + seconds;
  26.  
  27. draw_text(x,y,"Remaining Time:\n" + timerDisplay);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement