Danukem, on 23 June 2022 - 11:09 PM, said:
But it occurs to me that there may be a better method than either of those. As a sprite gets closer to sleeping, its .
httimetosleep member gets incremented. I have never researched the precise behavior of that counter, but what if the counter only gets lower when it is reset upon wakeup? If that's the case, then you could simply have the actor make the RECOG sound whenever httimetosleep is < what it was last tic:
ifl sprite[].httimetosleep sleeptime sound MYRECOG
geta[].httimetosleep sleeptime
As you thought it only lowers after the enemy is awakened again, it gives strange results though.
First I used
useractor myactor
ife sprite[].httimetosleep 0
sound MYRECOG
enda
This resulted in sleeping and reawakening enemies playing their RECOG properly, but enemies spawned via respawn didn't play the sound.
That made me think the respawning enemies have a higher initial value for httimetosleep, so I combined the above with the previous:
useractor myactor
ifvare temp1 0
{
sound MYRECOG
setvar temp1 1
}
else
ife sprite[].httimetosleep 0
sound MYRECOG
enda
This resulted in all forms of the enemy playing their sound after a 4 tick delay.
I figured that httimetosleep was somehow still being calculated on the first tick:
useractor myactor
ifvare temp1 1
{
ife sprite[].httimetosleep 0
sound MYRECOG
}
else
{
sound MYRECOG
setvar temp1 1
}
enda
but this results in even weirder behavior. All forms of enemies are playing the sound after ~4 tick delay but it doesn't always play.
It makes it seem like httimetosleep is starting with negative values and the times it doesn't play are where the increment skips 0.
But even in that case I don't understand why the bit following else is not working whenever ife sprite[].httimetosleep is used.
After messing around with it more I ended up with
useractor myenemy
ifvare temp1 0
{
sound MYRECOG
setvar temp1 1
}
else
ifvare temp1 1
{
ifcount 64
setvar temp1 2
}
else
ife sprite[].httimetosleep 0
sound MYRECOG
state actorcode
enda
and, as far as I've tested, this works
Thankfully when they fall asleep httimetosleep gets set to exactly 0