Having troubles with "timer" [SOLVED]

Started by Reven, Sun 02/04/2006 23:21:42

Previous topic - Next topic

Peder 🚀

I am having some problems with the SetTimer and IsTimerExpired codes.

Whenever the timer is set to have a TIMEOUT value over 1 it doesnt work.
If I put it on 1 it works..........


This is my code:
What I trying to do here is to make a wait function without the game pausing.
Cause I making a "shooting" game where the enemy will only shoot for example every third second.
The enemy can be hit 3 times before they die.
"cowshoot" is to tell the game if the cow is gonna shoot or not.
if 1 he shoots, if 2 he dont.

"cow" tells you what condition the enemy is in.
if 1 he is not hurt.
if 2 he has been shot once.
if 3 he has been shot twice.
(this is cause I show wounds on the character and need to give different views..)

Hope all this makes sence!

Code: ags

if (GetGraphicalVariable("cowshoot") == 1)
{
if (GetGraphicalVariable("cow") == 1)
{
SetTimer(1, 10);
if (IsTimerExpired(1) == 1) {
cCow.LockView(4);
cCow.Animate(0, 0, eOnce, eBlock, eForwards);
cCow.UnlockView();
cCow.Animate(0, 0, eRepeat, eNoBlock, eForwards);
SetGraphicalVariable("cowshoot", 2);
return; } }

if (GetGraphicalVariable("cow") == 2)
{
SetTimer(2, 1);
if (IsTimerExpired(2) == 1) {
cCow.LockView(4);
cCow.Animate(1, 0, eOnce, eBlock, eForwards);
cCow.UnlockView();
cCow.LockView(5);
cCow.Animate(3, 0, eRepeat, eNoBlock, eForwards);
SetGraphicalVariable("cowshoot", 2);
return; } }

if (GetGraphicalVariable("cow") == 3)
{
SetTimer(3, 1);
if (IsTimerExpired(3) == 1) {
cCow.UnlockView();
cCow.LockView(4);
cCow.Animate(2, 0, eOnce, eBlock, eForwards);
cCow.UnlockView();
cCow.LockView(5);
cCow.Animate(4, 0, eRepeat, eNoBlock, eForwards);
SetGraphicalVariable("cowshoot", 2);
return; } } }

//cowshoot == 1;
if (GetGraphicalVariable("cowshoot") == 2)
{
SetTimer(4, 2);
if (IsTimerExpired(4) == 1) {
SetGraphicalVariable("cowshoot", 1);
return; } }

Gilbert

#1
Timers don't work that way, setting a timer and then checking if it expires immediately is useless.

Normally, you need to start the timer when you need to:
SetTimer(1, 120);

And then check it continuously until it expires (commonly in repeatedly_execute() or repeatedly_execute_always() ):
if (IsTimerExpired(1)) Display("Blargh!1!");

Peder 🚀

Quote from: Gilbot V7000a on Mon 03/04/2006 02:26:30
Timers don't work that way, setting a timer and then checking if it expires immediately is useless.

Normally, you need to start the timer when you need to:
SetTimer(1, 120);

And then check it continuously until it expires (commonly in repeatedly_execute() or repeatedly_execute_always() ):
if (IsTimerExpired(1)) Display("Blargh!1!");

OK thanks!

Ill try and change my scripts.....

SMF spam blocked by CleanTalk