
-----------------------------------
Waked
Sat Jun 02, 2012 8:36 pm

How to make a Timer
-----------------------------------
im trying to make a timer for my game but im having some trouble with it and hope someone could help.
Thanks.
here is what i have so far:

setscreen ("offscreenonly")

var timeRunning : int := 0
var font := Font.New ("comicsansms:19:bold")

loop
    timeRunning := Time.Elapsed
    cls
    Font.Draw ("Time Running: " + intstr (round (timeRunning / 1000 / 60)) + ":" + intstr (round (timeRunning / 1000)), maxx div 2 - 105, maxy - 35, font, 7)
    View.Update
end loop

-----------------------------------
crossley7
Sat Jun 02, 2012 8:52 pm

Re: How to make a Timer
-----------------------------------
think about what your timer is doing then think which of the 3 rounding functions you want to use.
Round, floor, ceil.

Also, what is the highest value you want for the seconds part?  What mathematical function can you apply to what you have to ensure that is always the case.

I recommend you try to figure it out on your own, but if you highlight below, the answer will appear

Use floor and for the seconds, mod the value you have by 60

-----------------------------------
Waked
Sat Jun 02, 2012 8:55 pm

RE:How to make a Timer
-----------------------------------
Alright! thank you verry much!

-----------------------------------
Waked
Sat Jun 02, 2012 9:12 pm

RE:How to make a Timer
-----------------------------------
and also could you please helping me with displaying minutes and seconds as 2 digit numbers always?

-----------------------------------
crossley7
Sat Jun 02, 2012 10:01 pm

RE:How to make a Timer
-----------------------------------
just use separate if statements for if your minutes is less than 10, minutes is less than10 and both are less than 10.  Then just output an extra 0 where you need it to be.  With font.draw I think that is about as good a solution as you get

-----------------------------------
Waked
Sun Jun 03, 2012 9:23 am

RE:How to make a Timer
-----------------------------------
ok. Thanks :)
