Game Development Community

continuous counter

by Louis Marchant · in Torque 3D Beginner · 10/25/2012 (7:59 am) · 3 replies

me again ;) lol

just a quick question, i have a variable that needs to increment every xx ammount of time

but i neede ti to do this always, all the time, whole game, no conditions to it.

not sure where to go on this.

#1
10/25/2012 (8:21 am)
Somewhere convenient call a function that self schedules itself as often as you need it. Inside that scheduled function do your incrementing.

//somewhere after the game starts:
incrementCounter();

function incrementCounter()
{
   $someVariable++;
   schedule(1000, 0, "incrementCounter"); // 1000ms = ~1 second
}
#2
10/25/2012 (8:23 am)
note sure.
but i think u have to add code anywhere of main.cs from game folder.
better u add it at the end of onStart() function

$a=0;
$time=10000;//10 sec

function func()
{
$a++;
}

schedule(1000, 0, "func"); // 1000ms = ~1 second

i am not near my pc.so this code not tested.may be last line need some fix.look into script manual for correct prototype of schedule().

[edit]
michael's one perfect

#3
10/25/2012 (8:35 am)
thanks Michael, works a treat :)