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.

[RGSS]Wait in Ruby

Vear

Member

Hello, what command is doing the same thing as Wait event command? I need that to my script, and I don't want to add Wait after Call Script command. Please help me.
 
The wait command is 'command_106' of the Interpreter. It adds a specific value * 2 to the wait count. The wait count is then processed through an update if it's more than 0, causing no other commands to be continued until this count reaches 0 (removing 1 per loop). It's not a single command at that. But hey, if you add this simple code above main, you can do it just as easily:
Code:
class Interpreter
  def wait_command(wait)
    @wait_count = wait * 2
  end
end
Simply use this call script:
Code:
$game_system.map_interpreter.wait_command(frames)
Replace 'frames' with an integer value. 20 is the same as 20 frames.

Hope this helps.
 
Make a little counter like this:
Code:
class MyScene

  def main
    @wait_time = 0
    loop do
      #..
      #...
      update
    end
    #......
   end
  
  def update
    if @wait_time > 0
      @wait_time -= 1
      return
    end
    #...
  end
end

To wait some frames, use @wait_time = 10

Or, just use this:
Code:
sleep(1000)

I'd use @wait_time code, as it will update the graphics when waiting.
 

Zeriab

Sponsor

If you are using a Call Script event command for triggering the script then you use a variant of what Sheol made:
Code:
class MyObject
  def self.run(frames_to_wait)
    @@wait_time = frames_to_wait if @@wait_time.nil?
    if @@wait_time > 0
      @@wait_time -= 1
      return false  #return FalseClass if you are using SDK 2.4+
    end
    # Your code
    #...
    # Set @@wait_time to nil so the process can be repeated
    @@wait_time = nil
    # Continue event process
    return true
  end
end

Then just use this script call:
Code:
MyObject.run

Note that this will not work for SDK 2.3 and below.

There are more ways of doing what you want to achieve. My way will not work if you want multiply events to run MyObject.run at the same time.
Choose which version suits you best.

*hugs*
- Zeriab
 

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