Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / "undefined method 'draw' for nil:NilClass (NoMethodError)" ?
- - By imnofire Date 2016-04-16 03:58
I have recently started trying to code a game using Ruby and Gosu

I attempted to use a tutorial (https://corruptgd.wordpress.com/tutorials-creating-a-platformer-in-ruby-gosu/)
Unfortunately I am not even through the second part, and have gotten this error when trying to draw the Player

I have no idea what the problem is, or how I'm meant to fix it

Does anyone have any ideas?

EDIT: I'm using Ruby v1.9.3
Parent - - By jlnr (dev) Date 2016-04-16 07:20
Ha, I hadn't even seen this tutorial before. Nice :) I've gotten to the point where the player is first shown on the screen. There are two issues with this Tutorial that can lead to errors.
At one point in the example code, @sprite is mis-spelled as @spirte, and this would cause a NoMethodError, because @spirte is not assigned and instance variables (starting with @) are nil by default. The other issue is that the order in which things have to be called is important. GameWindow#initialize has to set $window to point to itself BEFORE creating the SceneMap`.

This is the code that I have so far, all in one file for simpler pasting: http://pastie.org/10799532

And by the way, there's no reason to use Ruby 1.9.3 with Gosu anymore. Ruby 1.8 through 2.2 are all supported, only 2.3 is missing right now :)
Parent - By imnofire Date 2016-04-16 10:46
thank you SOOOO much for this

I had seen the sprite/spirte mistake, and fixed it, but the $window = self thing was new to me, and the code you provided fixed the whole issue

btw, the only reason i used Ruby 1.9.3 is because i tried using 2.2, but the tutorial refused to work, including the guy's sample code for some reason, and i thought it may be a result of the version difference, now i know that isn't the case
Up Topic Gosu / Gosu Exchange / "undefined method 'draw' for nil:NilClass (NoMethodError)" ?

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill