Project1

标题: 请教判断变量$game_variables[2]的值是否有过一次小于0的时候 [打印本页]

作者: taeckle    时间: 2022-7-11 06:38
标题: 请教判断变量$game_variables[2]的值是否有过一次小于0的时候
本帖最后由 taeckle 于 2022-7-11 06:41 编辑

大家好,

我想在游戏进行到一定时候时在大地图上设置一个NPC, 这个NPC可以用来判断公共变量$game_variables[2]的值从游戏开始到现在是否有过小于0的时候
如果有的话则打开开关$game_switches[666],如果没有的话打开开关$game_switches[444],请问下这个判断又该怎么写呢?

if 公共变量$game_variables[2]的值从游戏开始到现在至少有过一次小于0的时候
$game_switches[666]=true
else
$game_switches[444]=true
end

还请大家多多指教,多谢啦!
作者: RyanBern    时间: 2022-7-11 10:25
本帖最后由 RyanBern 于 2022-7-11 10:28 编辑

随手写的,未测试。插入到 main 前。

RUBY 代码复制
  1. class Game_Variables
  2.   alias :rb_array_set_20220711 :[]=
  3.   def []=(variable_id, value)
  4.     @aux = true if variable_id == 2 && value < 0
  5.     rb_array_set_20220711(variable_id, value)
  6.   end
  7.   def v2_is_negative_since_game_start
  8.     @aux || false
  9.   end
  10. end


使用:
RUBY 代码复制
  1. if $game_variables.v2_is_negative_since_game_start
  2.   # do this
  3. else
  4.   # do that
  5. end

作者: taeckle    时间: 2022-7-14 07:00
RyanBern 发表于 2022-7-11 10:25
随手写的,未测试。插入到 main 前。

大神请问下这个@aux || false的意思就是吗:
  1. if @aux==false
  2. @aux=false
  3. else
  4. @aux=true
  5. end
复制代码






欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1