Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

"Wait 8 frames" in RGSS terms?

In RGSS, how do I get a script to "Wait 8 frames", for instance in Scene_Map, I have Walking Sound Effects written into the update method, but they must only play every 8 frames while the game player is moving depending on terrain, and they just play rapidly when I move. This is what I need to 'wait 8 frames' for, without halting the rest of Scene Map, so the sounds will play seamlessly instead of machine gun style.
 
How about if you create an instance variable and use it like a timer?
Lets say you added an instance variable in the Scene_Map's main method and set the value to 8, like this:

Code:
@wait = 8

Then in the update method you check if the timer is above 8, and if it is then you reduce the value in the variable by 1. And then you make another check to see if the "timer" has reached 0, and if it has, then you do whatever you want to do. Something like this:

Code:
  if $game_player.moving?
    if @wait > 0
      @wait -= 1
    end
    
    if @wait == 0
      $game_system.se_play($data_system.decision_se)
      @wait = 8
    end
  end

Since the update method updates every frame, it will reduce the "timer" by 1 every frame that the player is moving.
Which means that it will wait 8 frames before it playes the sound.
I don't know if there is a better way of doing this, but this is how i would do it.
Anyways, good luck with it Kain Nobel :thumb:

Over and out - Gando
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top