Something is wrong with this part of code. Not sure if the first row (which isn't right) is needed anyway.
Can someone please help me out with this?
The timer needs to run and get to the IsTimerExpired part.
Then the loop should restart the timer. The loop should be infinite.
And it's, of course, for the rep_exec.
Bool SetTimer = True
While 1
{ if(settimer ==true)
{(settime ==true)
{settimer(1,120);
Settimer = false;
}
If (istimerexpired(1))
{Display(“txtâ€);
Settimer=true
}
}
if (IsTimerExpired(1)) {
...
...
SetTimer(1, 120);
}
You need to start it once in game_start or a room's fadein.
@Khris
So the code I posted is not needed, only this little part you posted?
In the end it should change the background repeatedly, eg: gNoise.backgroundgraphic=6, gNoise.backgroundgraphic=7, gNoise.backgroundgraphic=8.
But this example with Display txt doesn't show any text at all:
function room_RepExec()
{
if (IsTimerExpired(1)) {
Display ("1");
Display ("2");
Display ("3");
SetTimer(1, 120);
}
}
Tried this, seems to work and seems to be infinite cause "cEgo.Say ("endloop");" is never shown.
But not sure if it is really OK:
function room_AfterFadeIn()
{
int i=0;
while(i<=1){
cEgo.Say ("2");
Wait (40);
cEgo.Say ("3");
Wait (40);
if (IsTimerExpired(1)) {
cEgo.Say ("endloop");
Wait (40);
SetTimer(1, 120);
i++;}
}
}
First of all, IsTimerExpired() will only work inside one of the repeatedly_execute functions.
Now, like I said, my code will only work if the timer is started manually once, e.g. inside one of the room's fadein functions. Otherwise, IsTimerExpired() in my code will never be true because the timer never got started.
What you did there won't work at all; Wait() halts the game until the number of loops has passed, it doesn't run in the background.
And:
int i=0;
while(i>=1){
The while block is skipped entirely, because obviously i isn't >= 1 if you just set it to 0.
Yes, the code I posted wasn't correct at all.
function room_RepExec()
{
cEgo.Say ("1");
cEgo.Say ("2");
if (IsTimerExpired(1)) {
cEgo.Say ("endloop");
Wait (40);
SetTimer(1, 120);
}
}
This seems to run though.... Is it correct this way?
Try this.
int timer;
function room_RepExec()
{
if (timer<40) {gNoise.backgroundgraphic=6; timer++;}
else if (timer<80) {gNoise.backgroundgraphic=7; timer++;}
else if (timer<120) {gNoise.backgroundgraphic=8; timer++;}
else timer=1;
}