じ☆ve冰风 发表于 2026-7-14 13:14:53

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
    when 0# switch
      result = ($game_switches[@parameters] == (@parameters == 0))
    when 1# variable
      value1 = $game_variables[@parameters]
      if @parameters == 0
      value2 = @parameters
      else
      value2 = $game_variables[@parameters]
      end
      case @parameters
      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]
      if @parameters == 0
          result = ($game_self_switches == true)
      else
          result = ($game_self_switches != true)
      end
      end
    when 3# timer
      if $game_system.timer_working
      sec = $game_system.timer / Graphics.frame_rate
      if @parameters == 0
          result = (sec >= @parameters)
      else
          result = (sec <= @parameters)
      end
      end
    when 4# actor
      actor = $game_actors[@parameters]
      if actor != nil
      case @parameters
      when 0# in party
          result = ($game_party.actors.include?(actor))
      when 1# name
          result = (actor.name == @parameters)
      when 2# skill
          result = (actor.skill_learn?(@parameters))
      when 3# weapon
          result = (actor.weapon_id == @parameters)
      when 4# armor
          result = (actor.armor1_id == @parameters or
                  actor.armor2_id == @parameters or
                  actor.armor3_id == @parameters or
                  actor.armor4_id == @parameters)
      when 5# state
          result = (actor.state?(@parameters))
      end
      end
    when 5# enemy
      enemy = $game_troop.enemies[@parameters]
      if enemy != nil
      case @parameters
      when 0# appear
          result = (enemy.exist?)
      when 1# state
          result = (enemy.state?(@parameters))
      end
      end
    when 6# character
      character = get_character(@parameters)
      if character != nil
      result = (character.direction == @parameters)
      end
    when 7# gold
      if @parameters == 0
      result = ($game_party.gold >= @parameters)
      else
      result = ($game_party.gold <= @parameters)
      end
    when 8# item
      result = ($game_party.item_number(@parameters) > 0)
    when 9# weapon
      result = ($game_party.weapon_number(@parameters) > 0)
    when 10# armor
      result = ($game_party.armor_number(@parameters) > 0)
    when 11# button
      result = (Input.press?(@parameters))
    when 12# script
      result = eval(@parameters)
    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 = !!result
    # If determinant results are true
    if @branch
      # 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 + "\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 + "\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.


本贴来自国际rpgmaker官方论坛作者:kyonides处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/script-commands-bug-fixes.154416/
页: [1]
查看完整版本: Script Commands Bug Fixes