所以我用红宝石写这个游戏,我有这个功能:
puts "Monsters that make you loose a hand-weapon"
for m in monsters
specificTreasures = Array.new
specificTreasures = m.bc.SpecificVisibleTreasures + m.bc.specificHiddenTreasures
for treasure in specificTreasures
if (treasure == TreasureKind::ONEHAND)
puts m.to_s
break
end
end
end
bc是“badconsequence”,bc指向一个“怪物”类,它有:
def initialize(name, level, prize, bc)
@name = name
#@combatLevel = level
@level=level
@prize = prize
@badConsequence = bc
end
和类badconsequence:
def initialize(aText, someLevels, someVisibleTreasures, someHiddenTreasures, someSpecificVisibleTreasures, someSpecificHiddenTreasures, death)
@text = aText
@levels = someLevels
@nVisibleTreasures = someVisibleTreasures
@nHiddenTreasures = someHiddenTreasures
@SpecificVisibleTreasures = someSpecificVisibleTreasures
@SpecificHiddenTreasures = someSpecificHiddenTreasures
@death = death
end
但它给了我这个错误: NoMethodError:nil的未定义方法`SpecificVisibleTreasures':NilClass
请帮忙吗?
答案 0 :(得分:0)
好的,谢谢大家,我已经修好了。它是其中一个类中的attr_accessor
,我使用不同的循环类型更改了主要内容:
monsters.each do |monstruo|
...
所以,就是这样,它现在有效。