设为首页收藏本站同能贴吧 切换语言 繁体中文
开启辅助访问 切换到窄版
扫描二维码关注官方公众号
返回列表
+ 发新帖
查看: 63|回复: 0

[转载发布] Script Commands Bug Fixes

[复制链接]
累计送礼:
0 个
累计收礼:
1 个
  • TA的每日心情
    开心
    前天 04:10
  • 签到天数: 209 天

    连续签到: 2 天

    [LV.7]常住居民III

    4461

    主题

    864

    回帖

    2万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    7
    卡币
    22929
    OK点
    16
    推广点
    0
    同能卷
    50
    积分
    28284

    灌水之王

    发表于 3 小时前 | 显示全部楼层 |阅读模式
    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:       
    1. # * Bug Fixes for Both of RMXP's Interpreter's Script Commands * #
    2. #   2025-02-12
    3. #   Result: You won't get any more issues with comannds returning nil values!
    4. class Interpreter
    5.   # * Conditional Branch * #
    6.   # Altered the Script Condition at the very end of this command
    7.   def command_111
    8.     # Initialize local variable: result
    9.     result = false
    10.     case @parameters[0]
    11.     when 0  # switch
    12.       result = ($game_switches[@parameters[1]] == (@parameters[2] == 0))
    13.     when 1  # variable
    14.       value1 = $game_variables[@parameters[1]]
    15.       if @parameters[2] == 0
    16.         value2 = @parameters[3]
    17.       else
    18.         value2 = $game_variables[@parameters[3]]
    19.       end
    20.       case @parameters[4]
    21.       when 0  # value1 is equal to value2
    22.         result = (value1 == value2)
    23.       when 1  # value1 is greater than or equal to value2
    24.         result = (value1 >= value2)
    25.       when 2  # value1 is less than or equal to value2
    26.         result = (value1 <= value2)
    27.       when 3  # value1 is greater than value2
    28.         result = (value1 > value2)
    29.       when 4  # value1 is less than value2
    30.         result = (value1 < value2)
    31.       when 5  # value1 is not equal to value2
    32.         result = (value1 != value2)
    33.       end
    34.     when 2  # self switch
    35.       if @event_id > 0
    36.         key = [$game_map.map_id, @event_id, @parameters[1]]
    37.         if @parameters[2] == 0
    38.           result = ($game_self_switches[key] == true)
    39.         else
    40.           result = ($game_self_switches[key] != true)
    41.         end
    42.       end
    43.     when 3  # timer
    44.       if $game_system.timer_working
    45.         sec = $game_system.timer / Graphics.frame_rate
    46.         if @parameters[2] == 0
    47.           result = (sec >= @parameters[1])
    48.         else
    49.           result = (sec <= @parameters[1])
    50.         end
    51.       end
    52.     when 4  # actor
    53.       actor = $game_actors[@parameters[1]]
    54.       if actor != nil
    55.         case @parameters[2]
    56.         when 0  # in party
    57.           result = ($game_party.actors.include?(actor))
    58.         when 1  # name
    59.           result = (actor.name == @parameters[3])
    60.         when 2  # skill
    61.           result = (actor.skill_learn?(@parameters[3]))
    62.         when 3  # weapon
    63.           result = (actor.weapon_id == @parameters[3])
    64.         when 4  # armor
    65.           result = (actor.armor1_id == @parameters[3] or
    66.                     actor.armor2_id == @parameters[3] or
    67.                     actor.armor3_id == @parameters[3] or
    68.                     actor.armor4_id == @parameters[3])
    69.         when 5  # state
    70.           result = (actor.state?(@parameters[3]))
    71.         end
    72.       end
    73.     when 5  # enemy
    74.       enemy = $game_troop.enemies[@parameters[1]]
    75.       if enemy != nil
    76.         case @parameters[2]
    77.         when 0  # appear
    78.           result = (enemy.exist?)
    79.         when 1  # state
    80.           result = (enemy.state?(@parameters[3]))
    81.         end
    82.       end
    83.     when 6  # character
    84.       character = get_character(@parameters[1])
    85.       if character != nil
    86.         result = (character.direction == @parameters[2])
    87.       end
    88.     when 7  # gold
    89.       if @parameters[2] == 0
    90.         result = ($game_party.gold >= @parameters[1])
    91.       else
    92.         result = ($game_party.gold <= @parameters[1])
    93.       end
    94.     when 8  # item
    95.       result = ($game_party.item_number(@parameters[1]) > 0)
    96.     when 9  # weapon
    97.       result = ($game_party.weapon_number(@parameters[1]) > 0)
    98.     when 10  # armor
    99.       result = ($game_party.armor_number(@parameters[1]) > 0)
    100.     when 11  # button
    101.       result = (Input.press?(@parameters[1]))
    102.     when 12  # script
    103.       result = eval(@parameters[1])
    104.     end
    105.     # Store determinant results in hash
    106.     # Added pos variable for the sake of convenience
    107.     pos = @list[@index].indent
    108.     # Bug Fix - Turn any nil value into false by default
    109.     @branch[pos] = !!result
    110.     # If determinant results are true
    111.     if @branch[pos]
    112.       # Delete branch data
    113.       @branch.delete(pos)
    114.       # Continue
    115.       return true
    116.     end
    117.     # If it doesn't meet the conditions: command skip
    118.     return command_skip
    119.   end
    120.   # * Script Event Command * #
    121.   # Just a small variant of a very old bug fix published by somebody else
    122.   def command_355
    123.     # Set first line to script
    124.     script = @list[@index].parameters[0] + "\n"
    125.     # Loop
    126.     loop do
    127.       # If next event command is second line of script or after
    128.       if @list[@index+1].code == 655
    129.         # Add second line or after to script
    130.         script += @list[@index+1].parameters[0] + "\n"
    131.       # If event command is not second line or after
    132.       else
    133.         # Abort loop
    134.         break
    135.       end
    136.       # Advance index
    137.       @index += 1
    138.     end
    139.     # Evaluation
    140.     result = eval(script)
    141.     # Removed Several Lines Here Before Continue
    142.     return true
    143.   end
    144. 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/

    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有账号?立即注册

    x
    天天去同能,天天有童年!
    回复 送礼论坛版权

    使用道具 举报

    文明发言,和谐互动
    文明发言,和谐互动
    高级模式
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    简体中文
    繁體中文
    English(英语)
    日本語(日语)
    Deutsch(德语)
    Русский язык(俄语)
    بالعربية(阿拉伯语)
    Türkçe(土耳其语)
    Português(葡萄牙语)
    ภาษาไทย(泰国语)
    한어(朝鲜语/韩语)
    Français(法语)
    关闭

    幸运抽奖

    社区每日抽奖来袭,快来试试你是欧皇还是非酋~

    立即查看

    聊天机器人
    Loading...

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2026-7-14 16:52 , Processed in 0.075319 second(s), 55 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

    快速回复 返回顶部 返回列表