查看: 2379|回复: 10

[已经解决] 请教在事件选择项中显示$game_temp里的属性值

[复制链接]
梦石
0
星屑
9160
在线时间
466 小时
注册时间
2015-5-8
回帖
704
发表于 2022-10-2 23:24:31 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

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

×
本帖最后由 taeckle 于 2022-10-2 23:33 编辑

大家好,

众所众知,在事件选择选项或者显示文章中可以用\v[1]表示第1号公共变量的内容,于是我也想搞一个在选择项中用\t.XXXXX表示$game_temp里对应的XXXXX值($game_temp.XXXXX),首先我在class Game_Temp里面attr_accessor新增了四个属性:
  attr_accessor :choice_one_c             # 选择项 选项一内容
  attr_accessor :choice_two_c             # 选择项 选项二内容
  attr_accessor :choice_three_c           # 选择项 选项三内容
  attr_accessor :choice_four_c            # 选择项 选项四内容  

然后给其都在 def initialize里就赋值, 最终目的当然是当我输入(\t.choice_one_c, \t.choice_two_c,\t.choice_three_c,\t.choice_four_c)时要能显示出对应内容出来, 我自己在Class Window_Message里面搞了半天都没搞出来,下面附上我的脚本(第94行),还请大家多多指教


  1. #==============================================================================
  2. # ■ Window_Message
  3. #------------------------------------------------------------------------------
  4. #  显示文章的信息窗口。
  5. #==============================================================================

  6. class Window_Message < Window_Selectable
  7.   #--------------------------------------------------------------------------
  8.   # ● 初始化状态
  9.   #--------------------------------------------------------------------------
  10.   def initialize
  11.     super(80, 304, 480, 160)
  12.     self.contents = Bitmap.new(width - 32, height - 32)
  13.     self.visible = false
  14.     self.z = 9998
  15.     @fade_in = false
  16.     @fade_out = false
  17.     @contents_showing = false
  18.     @cursor_width = 0
  19.     self.active = false
  20.     self.index = -1
  21.   end
  22.   #--------------------------------------------------------------------------
  23.   # ● 释放
  24.   #--------------------------------------------------------------------------
  25.   def dispose
  26.     terminate_message
  27.     $game_temp.message_window_showing = false
  28.     if @input_number_window != nil
  29.       @input_number_window.dispose
  30.     end
  31.     super
  32.   end
  33.   #--------------------------------------------------------------------------
  34.   # ● 处理信息结束
  35.   #--------------------------------------------------------------------------
  36.   def terminate_message
  37.     self.active = false
  38.     self.pause = false
  39.     self.index = -1
  40.     self.contents.clear
  41.     # 清除显示中标志
  42.     @contents_showing = false
  43.     # 呼叫信息调用
  44.     if $game_temp.message_proc != nil
  45.       $game_temp.message_proc.call
  46.     end
  47.     # 清除文章、选择项、输入数值的相关变量
  48.     $game_temp.message_text = nil
  49.     $game_temp.message_proc = nil
  50.     $game_temp.choice_start = 99
  51.     $game_temp.choice_max = 0
  52.     $game_temp.choice_cancel_type = 0
  53.     $game_temp.choice_proc = nil
  54.     $game_temp.num_input_start = 99
  55.     $game_temp.num_input_variable_id = 0
  56.     $game_temp.num_input_digits_max = 0
  57.     # 开放金钱窗口
  58.     if @gold_window != nil
  59.       @gold_window.dispose
  60.       @gold_window = nil
  61.     end
  62.   end
  63.   #--------------------------------------------------------------------------
  64.   # ● 刷新
  65.   #--------------------------------------------------------------------------
  66.   def refresh
  67.     self.contents.clear
  68.     self.contents.font.color = normal_color
  69.     x = y = 0
  70.     @cursor_width = 0
  71.     # 到选择项的下一行字
  72.     if $game_temp.choice_start == 0
  73.       x = 8
  74.     end
  75.     # 有等待显示的文字的情况下
  76.     if $game_temp.message_text != nil
  77.       text = $game_temp.message_text
  78.       # 限制文字处理
  79.       begin
  80.         last_text = text.clone
  81.         text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
  82.       end until text == last_text
  83.       text.gsub!(/\\[Nn]\[([0-9]+)\]/) do
  84.         $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
  85.       end
  86.       # 为了方便、将 "\\\" 变换为 "\000"
  87.       text.gsub!(/\\\\/) { "\000" }
  88.       # "\\C" 变为 "\001" 、"\\G" 变为 "\002"
  89.       text.gsub!(/\\[Cc]\[([0-9]+)\]/) { "\001[#{$1}]" }
  90.       text.gsub!(/\\[Gg]/) { "\002" }
  91.       
  92.       #这里是我增加的:
  93.       text.gsub!(/\\[Tt]\.\w+/) { eval("$game_temp." + $1 +"to_s") }
  94.       
  95.       # c 获取 1 个字 (如果不能取得文字就循环)
  96.       while ((c = text.slice!(/./m)) != nil)
  97.         # \\ 的情况下
  98.         if c == "\000"
  99.           # 还原为本来的文字
  100.           c = "\"
  101.         end
  102.         # \C[n] 的情况下
  103.         if c == "\001"
  104.           # 更改文字色
  105.           text.sub!(/\[([0-9]+)\]/, "")
  106.           color = $1.to_i
  107.           if color >= 0 and color <= 7
  108.             self.contents.font.color = text_color(color)
  109.           end
  110.           # 下面的文字
  111.           next
  112.         end
  113.         # \G 的情况下
  114.         if c == "\002"
  115.           # 生成金钱窗口
  116.           if @gold_window == nil
  117.             @gold_window = Window_Gold.new
  118.             @gold_window.x = 560 - @gold_window.width
  119.             if $game_temp.in_battle
  120.               @gold_window.y = 192
  121.             else
  122.               @gold_window.y = self.y >= 128 ? 32 : 384
  123.             end
  124.             @gold_window.opacity = self.opacity
  125.             @gold_window.back_opacity = self.back_opacity
  126.           end
  127.           # 下面的文字
  128.           next
  129.         end
  130.         # 另起一行文字的情况下
  131.         if c == "\n"
  132.           # 刷新选择项及光标的高
  133.           if y >= $game_temp.choice_start
  134.             @cursor_width = [@cursor_width, x].max
  135.           end
  136.           # y 加 1
  137.           y += 1
  138.           x = 0
  139.           # 移动到选择项的下一行
  140.           if y >= $game_temp.choice_start
  141.             x = 8
  142.           end
  143.           # 下面的文字
  144.           next
  145.         end
  146.         # 描绘文字
  147.         self.contents.draw_text(4 + x, 32 * y, 40, 32, c)
  148.         # x 为要描绘文字的加法运算
  149.         x += self.contents.text_size(c).width
  150.       end
  151.     end
  152.     # 选择项的情况
  153.     if $game_temp.choice_max > 0
  154.       @item_max = $game_temp.choice_max
  155.       self.active = true
  156.       self.index = 0
  157.     end
  158.     # 输入数值的情况
  159.     if $game_temp.num_input_variable_id > 0
  160.       digits_max = $game_temp.num_input_digits_max
  161.       number = $game_variables[$game_temp.num_input_variable_id]
  162.       @input_number_window = Window_InputNumber.new(digits_max)
  163.       @input_number_window.number = number
  164.       @input_number_window.x = self.x + 8
  165.       @input_number_window.y = self.y + $game_temp.num_input_start * 32
  166.     end
  167.   end
  168.   #--------------------------------------------------------------------------
  169.   # ● 设置窗口位置与不透明度
  170.   #--------------------------------------------------------------------------
  171.   def reset_window
  172.     if $game_temp.in_battle
  173.       self.y = 16
  174.     else
  175.       case $game_system.message_position
  176.       when 0  # 上
  177.         self.y = 16
  178.       when 1  # 中
  179.         self.y = 160
  180.       when 2  # 下
  181.         self.y = 304
  182.       end
  183.     end
  184.     if $game_system.message_frame == 0
  185.       self.opacity = 255
  186.     else
  187.       self.opacity = 0
  188.     end
  189.     self.back_opacity = 160
  190.   end
  191.   #--------------------------------------------------------------------------
  192.   # ● 刷新画面
  193.   #--------------------------------------------------------------------------
  194.   def update
  195.     super
  196.     # 渐变的情况下
  197.     if @fade_in
  198.       self.contents_opacity += 24
  199.       if @input_number_window != nil
  200.         @input_number_window.contents_opacity += 24
  201.       end
  202.       if self.contents_opacity == 255
  203.         @fade_in = false
  204.       end
  205.       return
  206.     end
  207.     # 输入数值的情况下
  208.     if @input_number_window != nil
  209.       @input_number_window.update
  210.       # 确定
  211.       if Input.trigger?(Input::C)
  212.         $game_system.se_play($data_system.decision_se)
  213.         $game_variables[$game_temp.num_input_variable_id] =
  214.           @input_number_window.number
  215.         $game_map.need_refresh = true
  216.         # 释放输入数值窗口
  217.         @input_number_window.dispose
  218.         @input_number_window = nil
  219.         terminate_message
  220.       end
  221.       return
  222.     end
  223.     # 显示信息中的情况下
  224.     if @contents_showing
  225.       # 如果不是在显示选择项中就显示暂停标志
  226.       if $game_temp.choice_max == 0
  227.         self.pause = true
  228.       end
  229.       # 取消
  230.       if Input.trigger?(Input::B)
  231.         if $game_temp.choice_max > 0 and $game_temp.choice_cancel_type > 0
  232.           $game_system.se_play($data_system.cancel_se)
  233.           $game_temp.choice_proc.call($game_temp.choice_cancel_type - 1)
  234.           terminate_message
  235.         end
  236.       end
  237.       # 确定
  238.       if Input.trigger?(Input::C)
  239.         if $game_temp.choice_max > 0
  240.           $game_system.se_play($data_system.decision_se)
  241.           $game_temp.choice_proc.call(self.index)
  242.         end
  243.         terminate_message
  244.       end
  245.       return
  246.     end
  247.     # 在渐变以外的状态下有等待显示的信息与选择项的场合
  248.     if @fade_out == false and $game_temp.message_text != nil
  249.       @contents_showing = true
  250.       $game_temp.message_window_showing = true
  251.       reset_window
  252.       refresh
  253.       Graphics.frame_reset
  254.       self.visible = true
  255.       self.contents_opacity = 0
  256.       if @input_number_window != nil
  257.         @input_number_window.contents_opacity = 0
  258.       end
  259.       @fade_in = true
  260.       return
  261.     end
  262.     # 没有可以显示的信息、但是窗口为可见的情况下
  263.     if self.visible
  264.       @fade_out = true
  265.       self.opacity -= 48
  266.       if self.opacity == 0
  267.         self.visible = false
  268.         @fade_out = false
  269.         $game_temp.message_window_showing = false
  270.       end
  271.       return
  272.     end
  273.   end
  274.   #--------------------------------------------------------------------------
  275.   # ● 刷新光标矩形
  276.   #--------------------------------------------------------------------------
  277.   def update_cursor_rect
  278.     if @index >= 0
  279.       n = $game_temp.choice_start + @index
  280.       self.cursor_rect.set(8, n * 32, @cursor_width, 32)
  281.     else
  282.       self.cursor_rect.empty
  283.     end
  284.   end
  285. end
复制代码

选择项显示$game_temp.rar

187.81 KB, 下载次数: 1

选择项显示$game_temp

梦石
0
星屑
2821
在线时间
585 小时
注册时间
2022-7-13
回帖
81
发表于 2022-10-2 23:38:52 | 显示全部楼层
尝试   \\t       。
回复

使用道具 举报

梦石
0
星屑
9160
在线时间
466 小时
注册时间
2015-5-8
回帖
704
 楼主| 发表于 2022-10-3 00:00:40 | 显示全部楼层
我为鱼肉 发表于 2022-10-2 23:38
尝试   \\t       。

还是不行。。。
回复

使用道具 举报

梦石
0
星屑
39336
在线时间
11161 小时
注册时间
2009-3-15
回帖
4768
发表于 2022-10-3 01:27:48 | 显示全部楼层
本帖最后由 soulsaga 于 2022-10-3 01:47 编辑
  1. text.gsub!(/\\[Tt].(\w+)/) { eval("$game_temp."+$1) }
复制代码

亲测有效

话说楼主你学默认脚本在def initialize里赋值啊
如果不在def initialize里赋值
即使不读旧存档这个变量也能使用

点评

只要加上def choice_one_c ;@choice_one_c ||="";end你不重开都可以用了 右边相当於初始值但不在def initialize里赋值就不用重新开始  发表于 2022-10-3 19:43
和存档无关..不信你试下不进行初始化看看能不能用?当然是不能  发表于 2022-10-3 19:40
这四个temp变量在initialize不赋值也可以用,我估计这是因为$game_temp不存储到存档里的缘故吧...  发表于 2022-10-3 19:09
1小时...  发表于 2022-10-3 07:04
关於def initialize里赋值好歹给个回应?  发表于 2022-10-3 07:01

评分

参与人数 2星屑 +50 赞 +1 收起 理由
RyanBern + 50 认可答案
taeckle + 1 精品文章

查看全部评分

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部