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

Project1

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

[已经解决] 脚本出现问题,麻烦翻译一下

 关闭 [复制链接]

Lv1.梦旅人

梦石
0
星屑
63
在线时间
61 小时
注册时间
2008-3-9
帖子
71
跳转到指定楼层
1
发表于 2009-8-11 10:21:28 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
错误类型为TypeError
no implicit conversion from nil to integer

出错行附近的脚本为:
  #--------------------------------------------------------------------------
  # ● 获取基本物理防御
  #--------------------------------------------------------------------------
  def base_pdef
    pdef1 = old_pdef
    slot1 = $data_armors[@slot1]
    slot2 = $data_armors[@slot2]
    slot3 = $data_armors[@slot3]
    slot4 = $data_armors[@slot4]
    slot5 = $data_armors[@slot1]
    slot6 = $data_armors[@slot2]
    slot7 = $data_armors[@slot3]
    pdef2 = slot1 != nil ? slot1.pdef : 0
    pdef3 = slot2 != nil ? slot2.pdef : 0
    pdef4 = slot3 != nil ? slot3.pdef : 0
    pdef5 = slot4 != nil ? slot4.pdef : 0
    pdef6 = slot5 != nil ? slot5.pdef : 0
    pdef7 = slot6 != nil ? slot6.pdef : 0
    pdef8 = slot7 != nil ? slot7.pdef : 0
    return pdef1 + pdef2 + pdef3 + pdef4 + pdef5 + pdef6 + pdef7 + pdef8
  end
  alias old_mdef base_mdef

出错的一行是slot1 = $data_armors[@slot1]
这种问题可能是哪里出错?应该从哪里入手解决?

Lv3.寻梦者

小空格

梦石
0
星屑
2595
在线时间
551 小时
注册时间
2009-7-15
帖子
1107
2
发表于 2009-8-11 10:33:54 | 只看该作者
你使用了错误的类型
{别找我,潜水去}
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
61
在线时间
24 小时
注册时间
2008-8-5
帖子
1924
3
发表于 2009-8-11 11:24:29 | 只看该作者
当你在把变量用在数组索引取值时,Ruby 会默认你这个变量是或者可以隐式转换为整数
这里 @slot1 为 nil,但是“nil 与 Integer 之间没有隐式转换”(所谓隐式转换就是不需要你强制去转换数据类型,编译器会自动转换),所以就发生异常了~

你的下手点就是检查 @slot1、@slot2 等等这些变量,这些变量都应该在对象实例化的时候或者调用 base_pdef 之前有一个初始值~
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-5-15 12:20

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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