设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 1491|回复: 10
打印 上一主题 下一主题

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

[复制链接]

Lv4.逐梦者

梦石
0
星屑
9128
在线时间
463 小时
注册时间
2015-5-8
帖子
865
跳转到指定楼层
1
发表于 2022-10-2 23:24:31 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
本帖最后由 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行),还请大家多多指教


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

选择项显示$game_temp.rar

187.81 KB, 下载次数: 1

选择项显示$game_temp

Lv3.寻梦者

梦石
0
星屑
2821
在线时间
585 小时
注册时间
2022-7-13
帖子
89
2
发表于 2022-10-2 23:38:52 | 只看该作者
尝试   \\t       。
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
9128
在线时间
463 小时
注册时间
2015-5-8
帖子
865
3
 楼主| 发表于 2022-10-3 00:00:40 | 只看该作者
我为鱼肉 发表于 2022-10-2 23:38
尝试   \\t       。

还是不行。。。
回复 支持 反对

使用道具 举报

Lv5.捕梦者

梦石
0
星屑
33213
在线时间
10497 小时
注册时间
2009-3-15
帖子
4756
4
发表于 2022-10-3 01:27:48 | 只看该作者
本帖最后由 soulsaga 于 2022-10-3 01:47 编辑

RUBY 代码复制
  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 精品文章

查看全部评分

回复 支持 反对

使用道具 举报

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

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-5-3 13:53

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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