Timer script trouble

Started by AndersM, Tue 26/10/2004 23:15:02

Previous topic - Next topic

AndersM

I hope that you script-nerds... Eee, I mean script-knowers :-X can help me with this:



This is my code:

function room_a() {
Ã,  // script for room: Player enters screen (before fadein)
SetTimer(1,1000);
IsTimerExpired(1)==1;
{DisplayMessage (9);}
}

with 40 cycles per second, it would take 25 seconds before the message is displayed, but it displays directly when the player enters the room.

I tried

function room_a() {
Ã,  // script for room: Player enters screen (before fadein)
SetTimer(1,1000);
If (IsTimerExpired(1)==1
{DisplayMessage (9);}
}

But it returned the message 'unidentified token If' or something like that.


What am I doing wrong?

And then some questions about timer: I beleave that the timer is supposed to be a 'you got five minutes to solve this mission' thing, that counts down not depending of what room you are in, right? But in this case, I want the timer to stop if the player leaves the room before timeout, and be re-set if he enters again.

Suggestions?



Ashen

#1
The second version looks nearly right, but:

1. There's a typo in the the IsTimerExpired() description in the manual - you need to use 'if' not 'If' (case sensitive, which is why you get the 'undefined token' message)

2. You missed the ) off the end of if (IsTimerExpired(1)==1)

3. If they don't help, try putting this bit:

if (IsTimerExpired(1)==1)
{DisplayMessage(9);}

in the room's repeatedly_execute. As it is, it might only display the message if the timer was expired when you entered the room, which it never will be.

EDIT:
Didn't see the second question.
I think you'd need to use a variable to keep track of where the timer was, and reset from that when you enter the room. I don't know if there's an easy way to do that, though. Sorry.

EDIT 2:
This is the way I'd do it:
1. Remove all references to the Timer - you won't need it.
2. Create an int in the room, called timer.
   (Open the Room Script, and add int timer; at the top, outside any functions)
3. Paste this code in to the repeatedly_execute:
Code: ags

  // script for room: Repeatedly execute
if (timer < 1000) timer++;
else if (timer == 1000) {
  DisplayMessage (9);
  timer ++;
}


This should do the same thing as a Timer, but will pause the countdown when you're not in the room, and pick up where it left off when you go back.
I know what you're thinking ... Don't think that.

AndersM

Thanx. I'll try this when I get home from work.

Typo in the manual... That's one of the reasons why I thaught about
including the mission 'Prevent Chris Jones from spreading AGS' in my game...

SMF spam blocked by CleanTalk