查看: 859|回复: 2

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

  [复制链接]
梦石
0
星屑
63
在线时间
61 小时
注册时间
2008-3-9
回帖
43
发表于 2009-8-11 10:21:28 | 显示全部楼层 |阅读模式

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

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

×
错误类型为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]
这种问题可能是哪里出错?应该从哪里入手解决?

小空格

梦石
0
星屑
2655
在线时间
555 小时
注册时间
2009-7-15
回帖
1023
发表于 2009-8-11 10:33:54 | 显示全部楼层
你使用了错误的类型
{别找我,潜水去}
回复

使用道具 举报

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

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

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部