查看: 2472|回复: 2

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

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

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

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

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

  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
复制代码
梦石
0
星屑
9557
在线时间
5074 小时
注册时间
2013-6-21
回帖
3459

开拓者贵宾剧作品鉴家

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

要想在别的类里面也能使用这个方法,最简单的办法就是重新定义一遍。
  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类的对象会显示在屏幕当中,并且这样调用也不合逻辑。
回复

使用道具 举报

梦石
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.

在本版发帖返回顶部