Project1
标题: 如何引用在Window Base里定义的text_color函数 [打印本页]
作者: 452234679 时间: 2016-5-22 08:19
标题: 如何引用在Window Base里定义的text_color函数
在Window_Base里定义了text_color函数,我在自己写的插件里引用这个函数会报错,请问应该怎么引用,是不是要先class一下?我新学脚本,还望高手指导,谢谢了
#--------------------------------------------------------------------------
# ● 获取文字色
# n : 文字色编号 (0~7)
#--------------------------------------------------------------------------
def text_color(n)
case n
when 0
return Color.new(255, 255, 255, 255)
when 1
return Color.new(128, 128, 255, 255)
when 2
return Color.new(255, 128, 128, 255)
when 3
return Color.new(128, 255, 128, 255)
when 4
return Color.new(128, 255, 255, 255)
when 5
return Color.new(255, 128, 255, 255)
when 6
return Color.new(255, 255, 128, 255)
when 7
return Color.new(192, 192, 192, 255)
else
normal_color
end
end
#--------------------------------------------------------------------------
# ● 获取文字色
# n : 文字色编号 (0~7)
#--------------------------------------------------------------------------
def text_color(n)
case n
when 0
return Color.new(255, 255, 255, 255)
when 1
return Color.new(128, 128, 255, 255)
when 2
return Color.new(255, 128, 128, 255)
when 3
return Color.new(128, 255, 128, 255)
when 4
return Color.new(128, 255, 255, 255)
when 5
return Color.new(255, 128, 255, 255)
when 6
return Color.new(255, 255, 128, 255)
when 7
return Color.new(192, 192, 192, 255)
else
normal_color
end
end
作者: RyanBern 时间: 2016-5-22 08:48
这个方法定义在Window_Base内部,因此只能在Window_Base以及它的子类中使用,在别的类中无法使用。
要想在别的类里面也能使用这个方法,最简单的办法就是重新定义一遍。
class A
def text_color(n)
case n
when 0
return Color.new(255, 255, 255, 255)
when 1
return Color.new(128, 128, 255, 255)
when 2
return Color.new(255, 128, 128, 255)
when 3
return Color.new(128, 255, 128, 255)
when 4
return Color.new(128, 255, 255, 255)
when 5
return Color.new(255, 128, 255, 255)
when 6
return Color.new(255, 255, 128, 255)
when 7
return Color.new(192, 192, 192, 255)
else
normal_color
end
end
end
class A
def text_color(n)
case n
when 0
return Color.new(255, 255, 255, 255)
when 1
return Color.new(128, 128, 255, 255)
when 2
return Color.new(255, 128, 128, 255)
when 3
return Color.new(128, 255, 128, 255)
when 4
return Color.new(128, 255, 255, 255)
when 5
return Color.new(255, 128, 255, 255)
when 6
return Color.new(255, 255, 128, 255)
when 7
return Color.new(192, 192, 192, 255)
else
normal_color
end
end
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 |