Coding Problem

I am just new to making RPG Maker games but I am familiar with programming logic and I am having a bit of trouble with my codes.
I'll make this short and simple.

My player is a robot and he is damaged from battle. I try to make it so after every five steps, he will show a balloon animation and lightning damage. But my problem is when running the game, it shows the balloon and lightning animation every step. What am I doing wrong here? Any help and criticism is appreciated. Thanks.

PS. This is also my first post here, so I apologize in advance if I violate some rules. Gomen~
Just a heads up for the future, in order to avoid confusion.
In RPGMaker "coding" refers to writing something in Javascript (or Ruby for earlier versions)
What you are referring to here are "event commands"

Do you need $gameplayer.isMoving() ? If the player is moving then the step counter will register it, if not then it won't.
I'll tell you what is wrong.
The parallel process runs in 60 fps, not once every step. That means it checks 60x per second whether the character is moving. However, the character needs 0.6s to move, during which the function isMoving will always return true.
That means you have like 40 consecutive frames of true. And every frame you increase the steps function by 1. Once it reaches 5, it plays the animation. Not just once, btw, but 7x-8x per step (unless you have Wait for animation turned on, which btw. would completely stop registering the steps until the animation finishes)
So you need to use wait commands.
Just a heads up for the future, in order to avoid confusion.
In RPGMaker "coding" refers to writing something in Javascript (or Ruby for earlier versions)
What you are referring to here are "event commands"

Do you need $gameplayer.isMoving() ? If the player is moving then the step counter will register it, if not then it won't.

I understand. Thank you and sorry for the confusion. $gameplayer.isMoving() seems to be working, and Poryg has pointed out what was wrong. Thanks again. 🙂

I'll tell you what is wrong.
The parallel process runs in 60 fps, not once every step. That means it checks 60x per second whether the character is moving. However, the character needs 0.6s to move, during which the function isMoving will always return true.
That means you have like 40 consecutive frames of true. And every frame you increase the steps function by 1. Once it reaches 5, it plays the animation. Not just once, btw, but 7x-8x per step (unless you have Wait for animation turned on, which btw. would completely stop registering the steps until the animation finishes)
So you need to use wait commands.

Thanks a lot! I tried showing a text window that displays many steps I had and it works. But when I removed them, the problem is still the same. That is probably because using text windows adds a certain delay to it. Where do you think I should insert the wait commands? Thanks a lot for your help. 🙂
The point of the wait command is to make the event check once per step, so anywhere is fine.
The point of the wait command is to make the event check once per step, so anywhere is fine.

Thanks a lot! I tried waiting for 40 frames but the animation did not show at exactly 5 steps. But it surely is better than what I had earlier. I will try experimenting with durations. Thanks!

Original thread: https://forums.rpgmakerweb.com/threads/coding-problem.83431/