Main‎ > ‎

Interpreter command_355 (RMXP)

posted Jan 7, 2010, 4:42 AM by Zeriab NA   [ updated Jan 9, 2010, 5:25 AM ]
This command has given people headaches and many don't really understand it.
In the default scripts if the script call is evaluated to false then the event waits and tries evaluating the script again.
Naturally if you don't think or accidentally cause false to be the result of the script call all the time, the event practically freezes.
An example could be $game_switches[42] = false which will evaluate to false every time. I really think that is not the purpose. Of course you could have $game_switches[42] to halt the event until that switch is turned on. This can have some nice practical purposes that I haven't seen.

The solution I most often see is: Oh god no! Let's remove it since it causes my game to freeze!
This is obviously not the most ideal solution. It is true that in practice many errors has been cause by the default behavior and considering how little people seem to use that feature it does seem to better to remove it than to keep it as it is.

As you can hear I am not too happy about the idea. It is a nice feature that I would want to keep. My solution would be to check if the call script evaluates to something which it is unlikely to do by accident. I have pushed through the check for FalseClass which is present in the SDK 2.4, but that doesn't really convey the purpose that well.
Checking for the :wait symbol is a nicer solution since it conveys what it means very well. I believe it's very unlikely that someone would make a call script which returns :wait by accident. It is at least much more unlikely than false.

Below is a script which also is compatible with the FalseClass version.

class Interpreter
  SCRIPT_WAIT_RESULTS = [:wait, FalseClass]
  # * Script
  def command_355
    # Set first line to script
    script = @list[@index].parameters[0] + "\n"
    # Store index in case we need to wait.
    current_index = @index
    # Loop
    loop do
      # If next event command is second line of script or after
      if @list[@index+1].code == 655
        # Add second line or after to script
        script += @list[@index+1].parameters[0] + "\n"
      # If event command is not second line or after
        # Abort loop
      # Advance index
      @index += 1
    # Evaluation
    result = eval(script)
    # If return value is false
    if SCRIPT_WAIT_RESULTS.include?(result)
      # Set index back (If multi-line script call)
      @index = current_index
      # End and wait
      return false
    # Continue
    return true

Notice that I also fixed the bug where it would not wait with multi-line call scripts.
If you want to also have support for false then you can change

      SCRIPT_WAIT_RESULTS = [:wait, FalseClass]


      SCRIPT_WAIT_RESULTS = [:wait, FalseClass, false]

You can also put in your own objects to check for.