[英]Ruby Gosu crash error: undefined method `*' for nil:NilClass
def update
if button_down?(Gosu::KB_SPACE) && !@pressed
@y -= 30
@pressed = true
elsif !button_down?(Gosu::KB_SPACE)
@pressed = false
end
if @vel.nil?
@vel *= 4
@y += @vel * 0.05
end
end
everytime i add an operator for @vel it gives me this error.每次我为@vel 添加一个运算符时,它都会给我这个错误。 Why's that?为什么?
tried checking if the variable is nil to run but none worked for me尝试检查变量是否为 nil 以运行但对我没有用
The conditional @vel.nil?
有条件的@vel.nil?
only returns true when @vel
is nil
.仅当@vel
为nil
时才返回 true 。 You want the opposite, either use .@vel?nil?
你想要相反的,要么使用.@vel?nil?
or use the unless
keyword instead of the if
keyword before @vel.nil?
或者在@vel.nil?
之前使用unless
关键字而不是if
关键字? . .
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.