查看: 2434|回复: 2

[已经解决] 如何引用在Window Base里定义的text_color函数

[复制链接]
梦石
0
星屑
55
在线时间
105 小时
注册时间
2016-4-3
回帖
50
发表于 2016-5-22 08:19:46 | 显示全部楼层 |阅读模式

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

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

×
在Window_Base里定义了text_color函数,我在自己写的插件里引用这个函数会报错,请问应该怎么引用,是不是要先class一下?我新学脚本,还望高手指导,谢谢了

[pre lang="ruby"]  #--------------------------------------------------------------------------
  # ● 获取文字色
  #     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[/pre]
梦石
0
星屑
9557
在线时间
5074 小时
注册时间
2013-6-21
回帖
3459

开拓者贵宾剧作品鉴家

发表于 2016-5-22 08:48:37 | 显示全部楼层
这个方法定义在Window_Base内部,因此只能在Window_Base以及它的子类中使用,在别的类中无法使用。

要想在别的类里面也能使用这个方法,最简单的办法就是重新定义一遍。
[pre lang="Ruby"]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[/pre]
另外,不推荐生成一个Window_Base对象之后再通过这个对象调用。这是因为Window_Base类的对象会显示在屏幕当中,并且这样调用也不合逻辑。
回复

使用道具 举报

梦石
0
星屑
55
在线时间
105 小时
注册时间
2016-4-3
回帖
50
 楼主| 发表于 2016-5-22 08:54:00 | 显示全部楼层
RyanBern 发表于 2016-5-22 08:48
这个方法定义在Window_Base内部,因此只能在Window_Base以及它的子类中使用,在别的类中无法使用。

要想在 ...

好的,谢谢您
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部