Script Commands Bug Fixes

Bug Fixes for Both of RMXP's Interpreter's Script Commands​

Introduction

For ages we've known very well that the RMXP Interpreter class had an issue with command_355 aka the script event command. It has to evaluate the result of a script pasted as mere text in a very small window.

The problem was that certain non truthy values, anything that doesn't return true as end result, might get ignored by the game engine. This part and its related solution are nothing new in the XP community and I just "copied & pasted" that centuries old solution here.

Nonetheless, that's not all this scriptlet has to offer. I was discussing some issues with XP in a VX ACE channel when I noticed there was another bug that usually got ignored in RMXP. It was the script condition in the conditional branch event command! Shocked

The issue is very simple. You open the conditional branch and choose the script condition and type something there that's supposed to return a boolean value. (No if conditional reserved term is required there.) Now you'd expect me to tell you that it had the same issue the script command has... but nope, that's not the case here.

Both a truthy (true) and a falsey (false) value are fine and work just as intended. Yet, here comes the dreadful nil value into play!

Whenever your call returns a nil, your check becomes invalid and the engine simply skips it. Just like that, guys! 😅

Don't worry pals! 😀
The scriptlet below has come to Save-Point to solve that issue! :issue:

The Script

Ruby:
# * Bug Fixes for Both of RMXP's Interpreter's Script Commands * #
#   2025-02-12
#   Result: You won't get any more issues with comannds returning nil values!

class Interpreter
  # * Conditional Branch * #
  # Altered the Script Condition at the very end of this command
  def command_111
    # Initialize local variable: result
    result = false
    case @parameters[0]
    when 0  # switch
      result = ($game_switches[@parameters[1]] == (@parameters[2] == 0))
    when 1  # variable
      value1 = $game_variables[@parameters[1]]
      if @parameters[2] == 0
        value2 = @parameters[3]
      else
        value2 = $game_variables[@parameters[3]]
      end
      case @parameters[4]
      when 0  # value1 is equal to value2
        result = (value1 == value2)
      when 1  # value1 is greater than or equal to value2
        result = (value1 >= value2)
      when 2  # value1 is less than or equal to value2
        result = (value1 <= value2)
      when 3  # value1 is greater than value2
        result = (value1 > value2)
      when 4  # value1 is less than value2
        result = (value1 < value2)
      when 5  # value1 is not equal to value2
        result = (value1 != value2)
      end
    when 2  # self switch
      if @event_id > 0
        key = [$game_map.map_id, @event_id, @parameters[1]]
        if @parameters[2] == 0
          result = ($game_self_switches[key] == true)
        else
          result = ($game_self_switches[key] != true)
        end
      end
    when 3  # timer
      if $game_system.timer_working
        sec = $game_system.timer / Graphics.frame_rate
        if @parameters[2] == 0
          result = (sec >= @parameters[1])
        else
          result = (sec <= @parameters[1])
        end
      end
    when 4  # actor
      actor = $game_actors[@parameters[1]]
      if actor != nil
        case @parameters[2]
        when 0  # in party
          result = ($game_party.actors.include?(actor))
        when 1  # name
          result = (actor.name == @parameters[3])
        when 2  # skill
          result = (actor.skill_learn?(@parameters[3]))
        when 3  # weapon
          result = (actor.weapon_id == @parameters[3])
        when 4  # armor
          result = (actor.armor1_id == @parameters[3] or
                    actor.armor2_id == @parameters[3] or
                    actor.armor3_id == @parameters[3] or
                    actor.armor4_id == @parameters[3])
        when 5  # state
          result = (actor.state?(@parameters[3]))
        end
      end
    when 5  # enemy
      enemy = $game_troop.enemies[@parameters[1]]
      if enemy != nil
        case @parameters[2]
        when 0  # appear
          result = (enemy.exist?)
        when 1  # state
          result = (enemy.state?(@parameters[3]))
        end
      end
    when 6  # character
      character = get_character(@parameters[1])
      if character != nil
        result = (character.direction == @parameters[2])
      end
    when 7  # gold
      if @parameters[2] == 0
        result = ($game_party.gold >= @parameters[1])
      else
        result = ($game_party.gold <= @parameters[1])
      end
    when 8  # item
      result = ($game_party.item_number(@parameters[1]) > 0)
    when 9  # weapon
      result = ($game_party.weapon_number(@parameters[1]) > 0)
    when 10  # armor
      result = ($game_party.armor_number(@parameters[1]) > 0)
    when 11  # button
      result = (Input.press?(@parameters[1]))
    when 12  # script
      result = eval(@parameters[1])
    end
    # Store determinant results in hash
    # Added pos variable for the sake of convenience
    pos = @list[@index].indent
    # Bug Fix - Turn any nil value into false by default
    @branch[pos] = !!result
    # If determinant results are true
    if @branch[pos]
      # Delete branch data
      @branch.delete(pos)
      # Continue
      return true
    end
    # If it doesn't meet the conditions: command skip
    return command_skip
  end
  # * Script Event Command * #
  # Just a small variant of a very old bug fix published by somebody else
  def command_355
    # Set first line to script
    script = @list[@index].parameters[0] + "\n"
    # 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
      else
        # Abort loop
        break
      end
      # Advance index
      @index += 1
    end
    # Evaluation
    result = eval(script)
    # Removed Several Lines Here Before Continue
    return true
  end
end

Infrequently Asked Questions

Q:
Has anybody else posted anything like this before?
A: Who knows? In any case I preferred to leave the script here just in case anybody fiddling with RMXP ever needs it.

Terms & Conditions

You can do whatever you want with it, I just built something upon somebody else's work and that's it.

Original thread: https://forums.rpgmakerweb.com/threads/script-commands-bug-fixes.154416/