Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby Chingu::GameWindow上的Chingu输入属性导致异常_Ruby - Fatal编程技术网

Ruby Chingu::GameWindow上的Chingu输入属性导致异常

Ruby Chingu::GameWindow上的Chingu输入属性导致异常,ruby,Ruby,这段代码在Chingu中引发了一个非常奇怪的异常,Chingu是一个依赖于Gosu 2D游戏框架的ruby游戏库: class StopSignAttack < Chingu::Window def initialize super(1000, 1000, false) self.input = { :escape => :close } self.caption = "Stop Sign ATTACK!!!" push_game_state(S

这段代码在Chingu中引发了一个非常奇怪的异常,Chingu是一个依赖于Gosu 2D游戏框架的ruby游戏库:

class StopSignAttack < Chingu::Window

  def initialize
    super(1000, 1000, false)
    self.input = { :escape => :close }
    self.caption = "Stop Sign ATTACK!!!"
    push_game_state(Start.new)
  end

end
当按下ESC键时,我会出现以下异常:

stop_sign_attack.rb:23:in `close': undefined method `close' for nil:NilClass (NoMethodError)
    from /Users/sams/.rvm/gems/ruby-1.9.3-p0/gems/gosu-0.7.41-universal-darwin/lib/gosu/swig_patches.rb:19:in `rescue in block (2 levels) in <class:Window>'
    from /Users/sams/.rvm/gems/ruby-1.9.3-p0/gems/gosu-0.7.41-universal-darwin/lib/gosu/swig_patches.rb:12:in `block (2 levels) in <class:Window>'
    from /Users/sams/.rvm/gems/ruby-1.9.3-p0/gems/gosu-0.7.41-universal-darwin/lib/gosu/swig_patches.rb:26:in `show'
    from /Users/sams/.rvm/gems/ruby-1.9.3-p0/gems/gosu-0.7.41-universal-darwin/lib/gosu/swig_patches.rb:26:in `show'
    from stop_sign_attack.rb:28:in `<main>'
stop\u sign\u attack.rb:23:in'close':nil:NilClass(NoMethodError)的未定义方法'close'
from/Users/sams/.rvm/gems/ruby-1.9.3-p0/gems/gosu-0.7.41-universal-darwin/lib/gosu/swig_patches.rb:19:in `分块救援(2级)'
from/Users/sams/.rvm/gems/ruby-1.9.3-p0/gems/gosu-0.7.41-universal-darwin/lib/gosu/swig_patches.rb:12:in `块(2层)in'
from/Users/sams/.rvm/gems/ruby-1.9.3-p0/gems/gosu-0.7.41-universal-darwin/lib/gosu/swig_patches.rb:26:in“show”
from/Users/sams/.rvm/gems/ruby-1.9.3-p0/gems/gosu-0.7.41-universal-darwin/lib/gosu/swig_patches.rb:26:in“show”
从停止符号开始攻击。rb:28:in`'

任何想法都将不胜感激。

您遗漏了一些信息,这些信息将允许有人对此进行调试。例如,您正在推一个名为Start的游戏状态,但在您的示例中没有声明Start类。但是你还没有分享那部分代码。我创建了以下示例项目,以测试您所获得的:

require 'chingu'

# A simple GameState-example
class Start < Chingu::GameState
end

class StopSignAttack < Chingu::Window

  def initialize
    super(1000, 1000, false)
    self.input = { :escape => :close }
    self.caption = "Stop Sign ATTACK!!!"
    push_game_state(Start.new)
  end

end

StopSignAttack.new.show
需要“chingu”
#一个简单的游戏状态示例
类开始:close}
self.caption=“停止标志攻击!!!”
推送游戏状态(开始。新建)
结束
结束
StopSignAttack.new.show

这一切都很好,当我按下escape时,毫无例外地退出。

你说得很好,但我承认我的故障排除还没有深入到那个程度。我在征求意见。
stop_sign_attack.rb:23:in `close': undefined method `close' for nil:NilClass (NoMethodError)
    from /Users/sams/.rvm/gems/ruby-1.9.3-p0/gems/gosu-0.7.41-universal-darwin/lib/gosu/swig_patches.rb:19:in `rescue in block (2 levels) in <class:Window>'
    from /Users/sams/.rvm/gems/ruby-1.9.3-p0/gems/gosu-0.7.41-universal-darwin/lib/gosu/swig_patches.rb:12:in `block (2 levels) in <class:Window>'
    from /Users/sams/.rvm/gems/ruby-1.9.3-p0/gems/gosu-0.7.41-universal-darwin/lib/gosu/swig_patches.rb:26:in `show'
    from /Users/sams/.rvm/gems/ruby-1.9.3-p0/gems/gosu-0.7.41-universal-darwin/lib/gosu/swig_patches.rb:26:in `show'
    from stop_sign_attack.rb:28:in `<main>'
require 'chingu'

# A simple GameState-example
class Start < Chingu::GameState
end

class StopSignAttack < Chingu::Window

  def initialize
    super(1000, 1000, false)
    self.input = { :escape => :close }
    self.caption = "Stop Sign ATTACK!!!"
    push_game_state(Start.new)
  end

end

StopSignAttack.new.show