Skip to content

Instantly share code, notes, and snippets.

@agmcleod
Created July 4, 2012 00:01
Show Gist options
  • Save agmcleod/3044254 to your computer and use it in GitHub Desktop.
Save agmcleod/3044254 to your computer and use it in GitHub Desktop.
Getting nil for a variable in one case but not another.
# player is in attr_accessor call inside the class.
# no error thrown
def render(gc, sbg, g)
@player.graphic
draw_surfaces
g.translate offset_x, offset_y
end
# (NoMethodError) undefined method `+' for nil:NilClass
def render(gc, sbg, g)
@player.graphic.draw((@player.x + offset_x), @player.y)
draw_surfaces
g.translate offset_x, offset_y
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment