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

Project1

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

[已经解决] draw_text引用换行符脚本出错

[复制链接]

Lv1.梦旅人

梦石
0
星屑
50
在线时间
94 小时
注册时间
2016-10-21
帖子
48
跳转到指定楼层
1
发表于 2017-6-17 21:36:42 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

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

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

x
本帖最后由 RyanBern 于 2017-6-19 09:37 编辑

这个脚本是用来draw_text可以使用换行符的,但导入出错了
报错下面有图片
这是脚本
RUBY 代码复制
  1. class Bitmap
  2.   alias :draw_text2 :draw_text unless defined? :draw_text2
  3.   def draw_text(*args)
  4.     case  args.size
  5.     when 2
  6.       rect = args[0]
  7.       text = args[1].split("\n")
  8.       align = 0
  9.     when 3
  10.       rect = args[0]
  11.       text = args[1].split("\n")
  12.       align = args[2]%3
  13.     when 5
  14.       rect = Rect.new(*(args[0,4]))
  15.       text = args[4].split("\n")
  16.       align = 0
  17.     when 6
  18.       rect = Rect.new(*(args[0,4]))
  19.       text = args[4].split("\n")
  20.       align = args[5]%3
  21.     else
  22.       raise ArgumentError,"错误的参数个数(#{args.size} to 2,3,5,6)."
  23.     end
  24.     return if text.empty?
  25.     wmax = [text.map{|t| self.text_size(t).width}.max,rect.width].min
  26.     h = self.text_size(text[0]).height
  27.     hmax = [h*text.size,rect.height].min
  28.     y = rect.y+(rect.height-hmax)/2
  29.     x = align==0 ? rect.x : align==2 ? rect.x+rect.width-wmax : rect.x+(rect.width-wmax)/2
  30.     text.each_with_index{|t,i|
  31.       draw_text2(x,y+i*h,wmax,h,t,align)
  32.     }
  33.     self
  34.   end
  35. end

捕获.PNG (26.57 KB, 下载次数: 5)

捕获.PNG

Lv5.捕梦者 (版主)

梦石
1
星屑
23984
在线时间
3339 小时
注册时间
2011-7-8
帖子
3926

开拓者

2
发表于 2017-6-18 06:12:37 | 只看该作者
会不会是,defined? 的参数是方法调用,而不是方法名(symbol对象),去掉defined?
后面的冒号看看

评分

参与人数 1星屑 +150 收起 理由
RyanBern + 150 6

查看全部评分

熟悉rgss和ruby,xp区版主~
正在填坑:《膜拜组传奇》讲述膜拜组和学霸们的故事。
已上steam:与TXBD合作的Reformers《变革者》
* 战斗调用公共事件 *
* RGSOS 网络脚本 *
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
94 小时
注册时间
2016-10-21
帖子
48
3
 楼主| 发表于 2017-6-18 12:04:15 | 只看该作者
guoxiaomi 发表于 2017-6-18 06:12
会不会是,defined? 的参数是方法调用,而不是方法名(symbol对象),去掉defined?
后面的冒号看看 ...

嗯,确实是,大神啊。

点评

不过是百度一下 defined? 的用法  发表于 2017-6-18 12:18
回复 支持 反对

使用道具 举报

Lv4.逐梦者 (版主)

梦石
0
星屑
9532
在线时间
5073 小时
注册时间
2013-6-21
帖子
3580

开拓者贵宾剧作品鉴家

4
发表于 2017-6-18 19:10:50 | 只看该作者
以下内容来自 rubydoc.org
纠正一下猫叔的说法,defined? 是关键字不是一个方法,所以说“参数”不太合适。改成“语法”[Synopsis]比较好。
defined?

defined? expression tests whether or not expression refers to anything recognizable (literal object, local variable that has been initialized, method name visible from the current scope, etc.). The return value is nil if the expression cannot be resolved. Otherwise, the return value provides information about the expression.

Note that the expression is not executed.

p defined?(def x; end)   # "expression"
x                        # error: undefined method or variable

p defined?(@x=1)         # "assignment"
p @x                     # nil

Assignment to a local variable will, however, have the usually result of initializing the variable to nil by virtue of the assignment expression itself:

p defined?(x=1)          # assignment
p x                      # nil

In most cases, the argument to defined? will be a single identifier:

def x; end
p defined?(x)            # "method"

评分

参与人数 1星屑 +66 收起 理由
guoxiaomi + 66 塞糖

查看全部评分

回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-9-21 18:48

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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