I have a player who is a cat, and want to have the cat sit after not having to have moved
I have this so far, but it's pretty buggy
on update do
updateFrame = event.frame
if event.dx==-1 then
swap "player-left"
elseif event.dx==1 then
swap "player-right"
elseif event.dy==1 then
elseif event.dy==-1 then
end
wait 3 then
if updateFrame > event.frame then
call "sit"
end
end
end
on sit do
swap "player-sit"
end
I would probably maintain my own timer using game’s loop event (passed to the player) and then only use player’s update to interrupt that timer. Something like this:
In the game’s script:
on loop do
tell event.player to
call "loop"
end
end
Then in the player:
on enter do
is_sitting = 0
sit_elapsed = 0
end
on loop do
if is_sitting==0 then
sit_elapsed += 1
if sit_elapsed>=60 then // 3 seconds
is_sitting = 1
tell event.player to
play "sit" then
swap "sleep"
end
end
end
end
end
on update do
sit_elapsed = 0
if is_sitting==1 then
is_sitting = 0
swap "player"
end
end
So first we set up our variables on enter. Then in our custom loop handler (which is called by the game’s native loop event) if we’re not already sitting we increment our timer. If the timer has run for 3 seconds (20fps * 3 seconds = 60 ticks) we tell the player to play their “sit” animation. play will play the animation once then stop. The optional block after that lets us use swap to start looping their sleeping animation. Then in the player’s update handler we reset our timer and if they’re already sitting, wake them up.
That worked great! Just had to integrate different directions. Thanks for the clear answer!
I wish the docs had more examples and more text about which events are used for what. Like sample use cases and more code examples. Also an AND and OR operator would be super helpful.