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.

Waiting Script

Well, Im stil waiting for help here, but I've realized that I'm not being very clear with what I really want. I posted a screenie of an event cammand window that mimics what I'm looking for. (it's in one of my more recent posts on the page) WHat I really want is a small script that I can use in another script to act just like the event command "wait", only based on a variable instead. What I'm trying to do is convert a bunch of old events I made a while ago into scripts. I don't really understand much RGSS, and from what I can tell, the examples that I was given just work when I reference them in an event. I would prefer it to be entirely script, if possible. Please, any help would be greatly appreciated. ^_^
 

khmp

Sponsor

Well what you are most likely doing is sticking in the loop the whole time when its counting up or down.

Code:
toast = 400
loop {
  toast -= 1
  break if toast == 0
}

That will wait for however amount of time it takes the your pc to subtract 1 from 400 until it reaches 0. That code is also about as helpful as sleep(400). If it doesn't hang up.

You need to break before you do the work you want waited on but still allow the rest of the code to execute. I'll add a wait feature to Game_System for a quick and easy example.

Code:
class Game_System
  alias_method :example_game_system_update, :update
  def update
    example_game_system_update
    # If wait exists and it does not equal zero update wait.
    if !@wait.nil? && @wait != 0
      # Update @wait
      @wait -= 1
      # If we are still waiting return.
      return if @wait > 0
    end
    # Here is where the work you want waited on would go.
  end

  def wait=(wait)
    @wait = wait
  end
end
 

Zeriab

Sponsor

If you are using RMXP you can also use the feature that one-line script calls evaluating to false will pause the event and be called again the next frame.
For example, you could try this script call.
Code:
$game_variables[6] <= 0
The event will now practically be paused until $game_variables[6] <= 0.
If the event is not on parallel process you won't be able to move the hero.

Here's another example: Let's assume you have this script: (To be placed in the script editor)
Code:
class Wait
  @@timers = {}
  def self.setup(key, wait)
    @@timers[key] = wait if wait.is_a?(Integer)
  end
  def self.wait(key)
    return true unless @@timers.key?(key)
    if @@timers[key] > 0
      @@timers[key] -= 1
      return false
    else
      return true
    end
  end
  def self.clear
    @@timers.clear
  end
end

If you have that script then you can by using 2 script call set it up to wait any number of frames.
First use Wait.setup(key, number) to set up a wait. The number is the amount of frames to wait. (20 frames = sec)
Next put Wait.wait(key) in a script call (and nothing else, one line only).
The key is same as what you put it the setup method. It can be pretty much anything. String, number, whatever. Just make sure you put the same in. This is to allow concurrent uses of the wait function.
Here are two example events:
http://img390.imageshack.us/img390/3660/waitscript1fq6.th.png[/img] http://img72.imageshack.us/img72/4679/waitscript2ng2.th.png[/img]

I am not totally sure what exactly you want to achieve so I might not have solved your problem. Either way I hope to have given you some insight ^_^

*hugs*
- Zeriab
 
Zeriab":1egdox89 said:
I am not totally sure what exactly you want to achieve so I might not have solved your problem. Either way I hope to have given you some insight ^_^

Well, I'm trying to achive something like the kind of timer you get when you do the following in an event:

Set a variable to, say, 50

Start a loop

wait for 20 frames

subtract 1 from the variable

set up a conditional branch for if the variable is equal to or less than 0, and break the loop if true.

repeat the loop.

I tried your script, as well as the initial suggestion, and I recieved the same results as with my own. (As in, it either gets ignored or it pauses until it is done) I'm probably doing something wrong, but I can't figure out what... What I'm trying to do is build a scripting equivalent of an old thunderstorm event that I built a while ago. I really am a n00b when it comes to building scripts, though. I DO understand what my main problem is, though. I can't seem to get the scripts to cycle more than once, and that is exactly what I need to do.
 

Zeriab

Sponsor

khmp":18xwq7c4 said:
A new perspective. Thanks Zeriab. Does that mean that event commands that return false in the interpreter are called until they return true?
if and only if the script call is 1 line. If you have more than 1 line then it will just continue.

That is probably why it won't work Glitchfinder. If you use more than 1 line in your script call.
Another possible reason why it won't work is if you use the SDK, because it 'fixes' (removes) that feature.

Here is another script you can try, which uses in game variables:
Code:
module Utility
  def self.wait_using_variable(variable_id)
    if $game_variables[variable_id] > 0
      $game_variables[variable_id] -= 1
      return false
    else
      return true
    end
  end
end
If you now set let's say variable 4 to 50. (Through the normal Control Switches event command)
Then you should put this in the next script call:
Code:
Utility.wait_using_variable(4)
It should now wait 50 frames, decreasing the variable once every frame. I know, it's not every 20 frames the variable is decreased, but every frame. You can get it to decrease every 20 frames, but that's more advanced.

Note: That this won't work if you got the SDK or some other Interpreter script call 'fix'. (It won't work on RMVX as well ^_^)

*hugs*
- Zeriab
 
Well, I've finally figured out the problems that I'm having with your scripts, Zeriab. Speciafically, I'm tryinf to convert one of my old events (that happens to be so complex that it takes a significant portion of my 512 MB RAM) into an entirely script-based form. Your scripts don't work when called internally. In fact, they act as though they don't even exist when called by another script. Thank you for the great help, but what I really need is something that will do the exact same thing as the event below, only entirely within a script.

http://img.photobucket.com/albums/v652/ ... titled.png[/img]
 

Zeriab

Sponsor

When called by another script... There's the reason. They should be calling using script calls in an event.
I thought you went for a hybrid between script and event, though as this is not the case do something like what khmp did.
Make a counter, set it to the appropriate value (60*20 = 1200 or 60*40 = 2400 (I am not sure how exactly smooth mode being on/off affects the amount of frames per second script-wise)) and decrease it by 1 every frame.
 
khmp":3ovay2hg said:
Well what you are most likely doing is sticking in the loop the whole time when its counting up or down.

Code:
toast = 400
loop {
  toast -= 1
  break if toast == 0
}

That will wait for however amount of time it takes the your pc to subtract 1 from 400 until it reaches 0. That code is also about as helpful as sleep(400). If it doesn't hang up.

You need to break before you do the work you want waited on but still allow the rest of the code to execute. I'll add a wait feature to Game_System for a quick and easy example.

Code:
class Game_System
  alias_method :example_game_system_update, :update
  def update
    example_game_system_update
    # If wait exists and it does not equal zero update wait.
    if !@wait.nil? && @wait != 0
      # Update @wait
      @wait -= 1
      # If we are still waiting return.
      return if @wait > 0
    end
    # Here is where the work you want waited on would go.
  end

  def wait=(wait)
    @wait = wait
  end
end

I'm not really sure how I can use this, if I can at all. I'm trying to figure out how to make a small portion of the script act in way that is identical to the wait event command, only based on a variable. (check my post with the event window) This is especially necessary for many of the things I am doing, because I used a very similar thing in many of the events that I am trying to recreate. I just can't make it stay in a loop and update at the same time. Any ideas?
 

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