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
每次我为@vel添加操作符时,它都会给我这个错误。为什么?
尝试检查变量是否为nil以运行,但没有为我工作
当@vel
为nil
时,条件@vel.nil?
才返回true。您需要的是相反的,使用!@vel.nil?
或在@vel.nil?
之前使用unless
关键字而不是if
关键字。