I'm making a game on Scratch in which the character has a walking animation. The walking animation is supposed to switch their costume to a walking stance, wait 0.5 seconds then go to an idle stance, wait 0.5 seconds then go to a walking stance, and repeat that until they let go of the button.
The image below is an image of the animation blocks put together that play the animation when walking left.
It worked perfectly until I added a block function for the same character when suddenly the animations broke for that character and the other one (who also has a walking animation with the same code). The second image below is an image of the blocking code.
After adding the block function, instead of waiting 0.5 seconds in between costume switches, it seems to switch to the walking stance and then immediately switch to the idle stance instead of waiting.
The image below shows the blocking blocks and the movement it controls. While they are blocking it isn't supposed to be able to move. That part works fine but I included it in case it has something else to do with my problem.
I tried running the piece of code shown individually (separate from the other animation parts) but the bug still occurs and the animation doesn't wait 0.5 seconds. I also tried changing the other character's animation so that it wouldn't activate when the animation broadcast was sent but it still bugged, which means:
I think the issue is with this part of your code. The forever loop is always trying to set the costume to the idle state when BlockStatus
is NonBlocking
.
This is then fighting with the loop that is trying to manage the swap between the idle and the walking costumes.
You may need to set a flag when the key is pressed and move the walking animation into this loop?