Hi guys! So, in this game I'm making, I try to reduce variable energy if the player walk or dash. I use this command in my common event
However, when I test the game, each step decreases CurrentEnergy variable by 30. Can someone help me out? Maybe it is related with my scriptcall? Thanks in advance!
your problem is that the parallel is executed once per frame, that is sixty times per second.
"is moving" only checks if the actor is moving, not how many steps were taken.
since it needs about half a second to complete the step, that costs you many points.
you basically need to check the position and remember the last position - if the coordinates have changed, then count for full step and update old position to not count again until next step.
Like Andar says, your Parallel event will process once per frame while switch 1 is turned on. Times taken for various move speeds are noted in this thread: link. The default player move speed is 4 (16 frames per step); if moving at speed 3, 1 tile of movement will take 32 frames and make $gamePlayer.isMoving() be true for 31 frames (final frame is at destination).
If you'd like to run something once per step instead, you can do a step count check each frame, e.g.
Code:
◆Comment:Get difference between stored step count and current step count
◆Control Variables:#0015 Step Count -= Steps
◆Comment:Has it changed since last check?
◆If:Step Count ≠ 0
◆Comment:It has changed!
◆Comment:Do things here that happen once per step
◆Show Balloon Icon:Player, Light Bulb
◆
:End
◆Comment:Store current step count in variable for next check~
◆Control Variables:#0015 Step Count = Steps
◆Comment:Check again in 6 frames
◆Wait:6 frames
[Edit: Steps can be found under Game Data > Other > Steps.]
...or you could use a plugin like this to toggle a parallel event's switch on step:
your problem is that the parallel is executed once per frame, that is sixty times per second.
"is moving" only checks if the actor is moving, not how many steps were taken.
since it needs about half a second to complete the step, that costs you many points.
you basically need to check the position and remember the last position - if the coordinates have changed, then count for full step and update old position to not count again until next step.
Like Andar says, your Parallel event will process once per frame while switch 1 is turned on. Times taken for various move speeds are noted in this thread: link. The default player move speed is 4 (16 frames per step); if moving at speed 3, 1 tile of movement will take 32 frames and make $gamePlayer.isMoving() be true for 31 frames (final frame is at destination).
If you'd like to run something once per step instead, you can do a step count check each frame, e.g.
Code:
◆Comment:Get difference between stored step count and current step count[/INDENT][/INDENT]
[INDENT][INDENT]◆Control Variables:#0015 Step Count -= Steps[/INDENT][/INDENT]
[INDENT][INDENT]◆Comment:Has it changed since last check?[/INDENT][/INDENT]
[INDENT][INDENT]◆If:Step Count ≠ 0[/INDENT][/INDENT]
[INDENT][INDENT] ◆Comment:It has changed![/INDENT][/INDENT]
[INDENT][INDENT] ◆Comment:Do things here that happen once per step[/INDENT][/INDENT]
[INDENT][INDENT] ◆Show Balloon Icon:Player, Light Bulb[/INDENT][/INDENT]
[INDENT][INDENT] ◆[/INDENT][/INDENT]
[INDENT][INDENT]:End[/INDENT][/INDENT]
[INDENT][INDENT]◆Comment:Store current step count in variable for next check~[/INDENT][/INDENT]
[INDENT][INDENT]◆Control Variables:#0015 Step Count = Steps[/INDENT][/INDENT]
[INDENT][INDENT]◆Comment:Check again in 6 frames[/INDENT][/INDENT]
[INDENT][INDENT]◆Wait:6 frames
...or you could use a plugin like this to toggle a parallel event's switch on step:
Thanks for your detailed response! Sadly, somehow the plugin freeze my game immediately. I tried to copy and paste your stamina common event system, and adjust the variables and switches accordingly, but it also freeze my game. For your posted parallel common event, I don't understand how these lines of algorithm can check my step count. And as I would expect, the value of variable 'CurrentEnergy' did not decrease at all. Would you be so kind to explain it to me in detail?
Edit : Just found out the 'steps' in control variables -> game data. I thought it was another variable altogether. Sorry for being dumb
Oh yes, sorry, I should have mentioned it's in Game Data > Other > Steps. I'll edit that in for future readers, good to hear you found it~
When you say "freeze", do you mean:
The game stopped visually updating or responding to any input (0 framerate)?
This sounds like a Loop without a Wait or Break Loop command, i.e. the game is trying to complete infinite commands in one frame. Check your project's events: you might have a problematic event that you forgot about that is linked to the switch you're using.
The game stopped responding to user input (movement, menu, etc) but otherwise seemed OK?
This sounds like an Autorun event: again, check the events on that map and/or all your common events. Autorun will suspend player input and trigger repeatedly while active; use Parallel for background tasks.
Also, did it freeze as soon as the map loaded, or only when you moved to another tile? You can show a framerate widget by pressing F2 during play, in case that helps.
The freezing is probably worth investigating even if your original problem is solved.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.