Project1

标题: 如何引用在Window Base里定义的text_color函数 [打印本页]

作者: 452234679    时间: 2016-5-22 08:19
标题: 如何引用在Window Base里定义的text_color函数
在Window_Base里定义了text_color函数,我在自己写的插件里引用这个函数会报错,请问应该怎么引用,是不是要先class一下?我新学脚本,还望高手指导,谢谢了

RUBY 代码复制
  1. #--------------------------------------------------------------------------
  2.   # ● 获取文字色
  3.   #     n : 文字色编号 (0~7)
  4.   #--------------------------------------------------------------------------
  5.   def text_color(n)
  6.     case n
  7.     when 0
  8.       return Color.new(255, 255, 255, 255)
  9.     when 1
  10.       return Color.new(128, 128, 255, 255)
  11.     when 2
  12.       return Color.new(255, 128, 128, 255)
  13.     when 3
  14.       return Color.new(128, 255, 128, 255)
  15.     when 4
  16.       return Color.new(128, 255, 255, 255)
  17.     when 5
  18.       return Color.new(255, 128, 255, 255)
  19.     when 6
  20.       return Color.new(255, 255, 128, 255)
  21.     when 7
  22.       return Color.new(192, 192, 192, 255)
  23.     else
  24.       normal_color
  25.     end
  26.   end

作者: RyanBern    时间: 2016-5-22 08:48
这个方法定义在Window_Base内部,因此只能在Window_Base以及它的子类中使用,在别的类中无法使用。

要想在别的类里面也能使用这个方法,最简单的办法就是重新定义一遍。
RUBY 代码复制
  1. class A
  2.   def text_color(n)
  3.     case n
  4.     when 0
  5.       return Color.new(255, 255, 255, 255)
  6.     when 1
  7.       return Color.new(128, 128, 255, 255)
  8.     when 2
  9.       return Color.new(255, 128, 128, 255)
  10.     when 3
  11.       return Color.new(128, 255, 128, 255)
  12.     when 4
  13.       return Color.new(128, 255, 255, 255)
  14.     when 5
  15.       return Color.new(255, 128, 255, 255)
  16.     when 6
  17.       return Color.new(255, 255, 128, 255)
  18.     when 7
  19.       return Color.new(192, 192, 192, 255)
  20.     else
  21.       normal_color
  22.     end
  23.   end
  24. end

另外,不推荐生成一个Window_Base对象之后再通过这个对象调用。这是因为Window_Base类的对象会显示在屏幕当中,并且这样调用也不合逻辑。
作者: 452234679    时间: 2016-5-22 08:54
RyanBern 发表于 2016-5-22 08:48
这个方法定义在Window_Base内部,因此只能在Window_Base以及它的子类中使用,在别的类中无法使用。

要想在 ...

好的,谢谢您




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