LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

Timers

Root / Submissions / [.]

joelableCreated:
What they do They could be used for many different things. Like if there is a time limit for a game you're making, then you might use a countdown timer. To see how long something takes, you could use a count up timer. How to make Heres a very simple loop I usually use:
@LOOP
PRINT TIME
INC TICK, 1
IF TICK==60 THEN
 INC TIME, 1
 TICK=0
ENDIF
WAIT 1
GOTO @LOOP
Time being the seconds or whatever, and tick being the milliseconds. These are always editable, like the line that's the IF statement, you can enlarge that value for a longer time and vice versa. Printing the time is, of course, unnecessary and it is possible to add another IF statement, this time checking for TIME instead of TICK so that when the time reaches a certain point, something will happen. Also, for countdowns, use DEC instead of INC inside the IF statement, that will make the time value go down instead of up, and make sure to set the value of time before the loop.

Cool

A more robust and flexible way to implement timers is to use MAINCNT. At the beginning of the period you want to measure, set a variable (say, TIME0) to the value of MAINCNT. At any point later in the program, the expression MAINCNT-TIME0 will give the number of 'ticks' (units of 1/60th of a second) between then and 'now', the time at which the expression is evaluated.

Replying to:SquareFingers
A more robust and flexible way to implement timers is to use MAINCNT. At the beginning of the period you want to measure, set a variable (say, TIME0) to the value of MAINCNT. At any point later in the program, the expression MAINCNT-TIME0 will give the number of 'ticks' (units of 1/60th of a second) between then and 'now', the time at which the expression is evaluated.
I see. Thanks for the help. I would have never thought of that.

Replying to:SquareFingers
A more robust and flexible way to implement timers is to use MAINCNT. At the beginning of the period you want to measure, set a variable (say, TIME0) to the value of MAINCNT. At any point later in the program, the expression MAINCNT-TIME0 will give the number of 'ticks' (units of 1/60th of a second) between then and 'now', the time at which the expression is evaluated.
Another outside the box way is to use SPANIM on a sprites variable #7. You can check it with SPCHK. This has limitations in how high the counter can go; but runs at a constant 60 fps no matter what.