|
Lucius Nesterov
Registered User
Join date: 12 Oct 2006
Posts: 33
|
05-08-2007 02:39
I'm having some difficulty with a game that I'm making. It uses turns where players have 20 seconds to enter moves in a HUD; then it collects them and animates some characters. There's an image at http://lucius-games.blogspot.com/ (Spider-Fly game). I thought it was all working, but I have a problem with the timers. The first time the game is played it runs ok, but in following games on the first turn when it is supposed to wait for 20 seconds it doesn't wait at all. I've included a section of code below that includes all timer related calls. So the problem is in the start_turn state, on the first turn of games it jumps straight to the timer() without waiting. I tried adding a llSetTimerEvent(0) before asking it to wait 20 seconds, but it had no effect. Does anyone have any suggestions? state start_turn { state_entry() { // Announce turn is starting
// Allow 20 seconds for players to enter commands llSetTimerEvent(20.0); } timer() { // Ask player HUDs to send commands // Count which have replied - handled by a listen function
// If both player HUDS have replied if (replyCount==2) { llSetTimerEvent(0); // Cancel timer state run_anim; // Act out commands } else { timerState++; // Keep track of failed requests if (timerState>=4) // If asked twice with no reply { // Timed out if (replyCount==1) { llSetTimerEvent(0); // Cancel timer state run_anim; // If one replied, follow their commands } else state default; // If neither replied, reset the game } // Set a pause before asking again llSetTimerEvent(2.0); } } }
state run_anim { state_entry() { // Announce start of animation llSetTimerEvent(0.2); } timer() { if (commandLoop<4) { // Animate commands
// Check for game end conditions
llSetTimerEvent(1.0); // pause between commands } else { // All commands finished. Back to turn start llSetTimerEvent(0); state start_turn; } } }
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
05-08-2007 03:33
Your code appears to be allowing you to drop through with out clearing the timer event. I'd suggest adding a llSetTimerEvent(0) in state_entry of default.
|
|
Squirrel Wood
Nuteater. Beware!
Join date: 14 Jun 2006
Posts: 471
|
05-08-2007 04:02
Timers go bonkers if you don't turn them off on exiting a state.
So I suggest you add a...
state_exit() { llSetTimerEvent(0.0); }
to each state.
|
|
Lucius Nesterov
Registered User
Join date: 12 Oct 2006
Posts: 33
|
05-09-2007 02:28
Thanks for your help. Resetting the timer in the state_entry of default worked, although its a hack I'd prefer not to have to use.
I'll have to try and find where the timer is leaking out.
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
05-09-2007 03:08
From: Lucius Nesterov Thanks for your help. Resetting the timer in the state_entry of default worked, although its a hack I'd prefer not to have to use.
I'll have to try and find where the timer is leaking out. As timers are persistent you should either clear them on state_exit or on state_entry either performs the required function. Its far from a hack although I understand why you say so. As for where the leak is its here else state default; // If neither replied, reset the game
_____________________
I'm back......
|