Page 1 of 1

Self is a nil value

Posted: Sat Aug 31, 2024 9:16 pm
by TheSilentor
I was following a series of tutorials on how to create a platformer when I got to the point where you're supposed to draw the player aka a rectangle. I followed along and pressed alt + l to see it run when I got this error:

Error

Player.lua:31: bad argument #2 to 'rectangle' (number expected, got nil)


Traceback

[love "callbacks.lua"]:228: in function 'handler'
[C]: in function 'rectangle'
Player.lua:31: in function 'draw'
main.lua:20: in function 'draw'
[love "callbacks.lua"]:168: in function <[love "callbacks.lua"]:144>
[C]: in function 'xpcall'


I triple checked my code and It should work, but it doesn't. :?

Re: Self is a nil value

Posted: Wed Sep 04, 2024 12:24 am
by Hugues Ross
I'm pretty sure you just missed a call to Player:load(). Without that, you won't have any values in 'self' when calling Player:draw()--that's what your error is here, self is a real value but self.x is nil

Also...unrelated, but "Map/1..lua" looks like a possible typo. Can't say for sure with the fragments of the project that are here, but probably worth double checking.