If i wanted a object to wait a few seconds before doing the next command how do i do that? I also want the player to be able to move while thats happening.
Normally you'd just use Wait ();
But since you want it to be non blocking you should use a timer
Check out
IsTimerExpired and SetTimer in the manual, and you should be all set...
I used the code:
SetTimer(1,1000);
if (IsTimerExpired(1)==1)
{ObjectOff (3);
DisableHotspot (6);
}
but that didn't work.
I'd recommend the next method:
at the top of room script:
int counter = 0; // holds current action number (counter=0; rewind execution and start again)
int run = 0; // if run=1 starts action, run=0 pause
function ObjectActions() {
if (counter == 1) ObjectCommand1();
else if (counter == 50) ObjectCommand2();
else if (counter == 100) ObjectCommand3();
else if (counter == 150) ObjectCommand4();
counter = counter + run; //goto next action
}
room's repeatedly:
ObjectActions();
Now, whenever you want for object to execute the commands you put:
run = 1;
if you put run =0; then execution holds on
setting counter = 0; will force it to rewind to the 1st action.
Now how to control these pause delays between commands. just change the bold numbers the way that the more the difference is the longer pause will be. Only one rule: the next value should be greater than the previous one (keeping it this way ensures the commands will be executed in exactly the same order as they are listed in).
How does it go?
undefined token Objectcommand
Put your won commands in those places...
if it is a variable you need to define it:
int variable();
Example:
...
if (counter == 1) MoveObject(1, 100 ,100, 2); //move object
else if (counter == 50) AnimateObject(1, 0, 3, 1); //animate object
else if (counter == 100) MoveObject(1, 100 ,200, 2); //move object
else if (counter == 150) Display("that's all"); //display a message
...
Quoteif it is a variable you need to define it:
int variable();
you don't need the parentheses:
int variable;
~Cheers
ok scorpiorus.
i was thinking of c++^_^
I don't know if this is the case here, but there can be a problem if you create your own counter instead of using the 'settimer' 'istimerexpired' commands. (note: this is for a non blocking scene, which I think is the case here)
eg. if you bring up the save/load gui or any other gui the timer still counts and depending on other scripts the buttons might be grayed out and the game will just pause there without being able to get back. But if you use the 'settimer' 'istimerexpired', the timer will be paused while the gui is on.
The easy way to solve that problem is to simply put an if (IsGamePaused() == 0) { around the portion of the repeatedly execute that makes the counter count up. That way, as soon as someone pauses the game, brings up a GUI, causes a blocking command, the counter will no longer count up.
~Wolfgang
Quote from: Hindersh_screwed_xp on Sun 11/01/2004 00:53:46
ok scorpiorus.
i was thinking of c++^_^
That's ok, :) I just want to make it more precise (since that way of declaration doesn't work in AGS).
QuoteI don't know if this is the case here, but there can be a problem if you create your own counter instead of using the 'settimer' 'istimerexpired' commands.
It's a good point actually. And Wolfgang suggested a rational workaround which I completely forgot to mention about, so the repeatedly part of the script I posted should be:
room's repeatedly:if (IsGamePaused()==0) ObjectActions();
This way the timer is stopped when the game is paused (ex: pop-up modal GUI is shown)
This is because the repeatedly_execute is still called whenever the game is paused (if the script is blocked the repeatedly function is not called in either way). And therefore executing commands while the game is paused appears to be the only way to de-sync game process.
~Cheers
SetTimer(1,1000);
if (IsTimerExpired(1)==1)
{ObjectOff (3);
DisableHotspot (6);
}
that code wouldn't work because the first time it checks if the timer is 1000 its probably only 1 or something.
So i repeatedly checked to see if the timer was gone.
Anyway, this is a much simpler way to do things. i don't like to much scripting, Mainly 'cause i don't know much.
Thx for all you time.
Ps. I saved all of the replies for later reference. ;)