Code:
var counter;
var counter_state = 0; //0 = not counting, 1 = counting
function counter_set(_state,_value)
{
counter = _value;
while(counter_state)
{
counter -= 1;
counter_state *= sign(counter);
wait(-1);
}
}
function counter_add(_value)
{
counter += _value;
}
//Start the counter like this (e.g. 20 seconds):
counter_set(1,20);
//End the counter like this:
counter_set(0,0);
//Add something to the counter (e.g. +40 seconds):
counter_add(40);
//player did something wrong, give him less time (-20):
counter_add(-20);