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.
Self is a nil value
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 1
- Joined: Sat Aug 31, 2024 9:03 pm
Self is a nil value
- Attachments
-
- player.lua
- Player File (Where Issue Is)
- (776 Bytes) Downloaded 190 times
-
- main.lua
- Main File
- (444 Bytes) Downloaded 172 times
-
- conf.lua
- Config File
- (141 Bytes) Downloaded 175 times
- Hugues Ross
- Party member
- Posts: 112
- Joined: Fri Oct 22, 2021 9:18 pm
- Location: Quebec
- Contact:
Re: Self is a nil value
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.
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.
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 5 guests