Counter

Posted By: Skeksis

Counter - 06/08/08 11:33

This is probably going to sound really noobish, but I'm not much of a programmer. Bassically I'm working on a simple boxing game, I'm using the script below as a timer for the rounds, it counts down 2 minutes, when it reaches zero the next round starts. The problem is I can't seem to reset the timer at the start of each round, it just stays at zero, I hope that made sense.

string time_str;
string temp_str;

var seconds = 120; // number of seconds to be counted down
var temp_seconds;


function count_down()

{
while(seconds > 0)

{
sleep (1);
seconds -= 1;
temp = int(seconds / 60); // compute the number of minutes
str_for_num(time_str, temp);
str_cat (time_str, " : ");
temp_seconds = seconds - temp * 60; // compute the remainder (the number of seconds)
str_for_num(temp_str, temp_seconds);
if (temp_seconds < 10)
{
str_cat (time_str, "0"); // add a zero (if needed)
}
str_cat (time_str, temp_str);

}
}
Posted By: Xarthor

Re: Counter - 06/08/08 13:09

When a new round start call a function which does something like the following:
Code:
function start_NewRound()
{
  seconds = 120;
  count_down();
}


btw:
Instead of sleep(x); use wait(-x);
Because sleep is old syntax
Posted By: Skeksis

Re: Counter - 06/08/08 13:25

That worked, thanks for the help, I should have been able to figure it out myself.
Posted By: DJBMASTER

Re: Counter - 06/08/08 23:31

Did it even run with "sleep"? I thought the engine would have refused to run with the old syntax, are you using A7?
Posted By: Skeksis

Re: Counter - 06/09/08 07:35

I didn't try running it with sleep, I changed it to wait(-1), The only reason it had sleep in the script I posted is because I copied it from the original file and not from the file in my project.
Posted By: testDummy

Re: Counter - 06/09/08 08:29

hypothetical error event: multiple count_down() functions in engine's function list?
solvent / insurance: one instance only? proc_kill?
count_down()
count_down()
count_down()
count_down()
count_down()
count_down()
// close on n not down to other n
(Of end and beginning, Mistress Cosmos, is blind, persistent, and uncaring, with respect to primates, appendages, and digits.)
© 2024 lite-C Forums