Trouble with Lua Love, Pong, and nil should be a number
Posted: Mon Jul 20, 2020 12:57 am
--First and foremost, I tried a -lot- of stuff (or it seems that way to me), so there's a lot of info here. I apologize if it's a long read, I just want to be thorough. I also want to let everyone to know what I already tried...maybe you're be more inclined to help??--
I am having an issue with coding the Pong remake from Harvard's CS50 games track. Tried many things, posted below, and looked at 10 pages of posts about 'pong nil value' on this site. In my age-old wisdom at 34, I'm just sure I've tried everything
Using:
Windows 7 64-bit x64
For each attempted solution/debug, I tried with each of these:
Sublime Text 3 and
VSCode
Lua 5.1 and
Lua 5.3
LOVE 10.2 and
LOVE 11.3
--LOVE FILE-- Most recent error MSG:
While stepping into and through the debugger, I got to:
It jumped to push.lua in same folder, and on line 8:
and threw this:
________________________________________________________________________________________________________
PROBLEM INFO:
I've tried variations, even hard coding values in the individual class files, such as (for variations of this problem where that was supposedly the failure).
It always comes down to expecting a number but getting nil.
Sometimes the error involves trying to draw the rectangles in one class file or the other, sometimes it involves trying to do math with a nil value in one class file or another. Sometimes, it says such-and-such (like self.y in Paddle.lua) is nil when it should be a number--you get the idea.
I downloaded the distribution code from the Harvard Games Track page telling me to make an artificial intelligence or two to play the game, and the distro build works just fine. I've looked back over everything from both his videos up to my point (Pong 5, for those who've done it), as well as comparing the parts of the distro covered up till vid Pong 5 to my own. I can't seem to find an error.
I've also changed quite a bit from where I had followed up till Pong 5, just playing around with it trying to see what isn't working--adding/removing print statements, using VSCode's debug feature with a Lua debugger extention--so at this point there may well be a lot of bugs.
________________________________________________________________________________________________________
Inspired from what I found in HERE, I tried using instead of .
I tried dragging my Games Track folder onto the LOVE 11.3 and LOVE 10.2 icons, also, and it gave the same error. Colten's Pong distro folder works, though.
I am having an issue with coding the Pong remake from Harvard's CS50 games track. Tried many things, posted below, and looked at 10 pages of posts about 'pong nil value' on this site. In my age-old wisdom at 34, I'm just sure I've tried everything
Using:
Windows 7 64-bit x64
For each attempted solution/debug, I tried with each of these:
Sublime Text 3 and
VSCode
Lua 5.1 and
Lua 5.3
LOVE 10.2 and
LOVE 11.3
--LOVE FILE-- Most recent error MSG:
Code: Select all
Error
Paddle.lua:34: bad argument #2 to 'rectangle' (number expected, got nil)
Traceback
[C]: in function 'rectangle'
Paddle.lua:34: in function 'render'
main.lua:134: in function 'draw'
[C]: in function 'xpcall'
While stepping into and through the debugger, I got to:
Code: Select all
push = require 'push'
It jumped to push.lua in same folder, and on line 8:
Code: Select all
local love11 = love.getVersion() == 11
and threw this:
Code: Select all
Exception has occurred: push.lua:8: attempt to index a nil value (global 'love')
stack traceback:
push.lua:8: in main chunk
[C]: in function 'require'
main.lua:26: in main chunk
[C]: in ?
PROBLEM INFO:
I've tried variations, even hard coding values in the individual class files, such as
Code: Select all
self.x = 1, self.y = 1, self.width = 1, and self.height = 1 --in [Paddle.lua's Paddle:update(dt) function
It always comes down to expecting a number but getting nil.
Sometimes the error involves trying to draw the rectangles in one class file or the other, sometimes it involves trying to do math with a nil value in one class file or another. Sometimes, it says such-and-such (like self.y in Paddle.lua) is nil when it should be a number--you get the idea.
I downloaded the distribution code from the Harvard Games Track page telling me to make an artificial intelligence or two to play the game, and the distro build works just fine. I've looked back over everything from both his videos up to my point (Pong 5, for those who've done it), as well as comparing the parts of the distro covered up till vid Pong 5 to my own. I can't seem to find an error.
I've also changed quite a bit from where I had followed up till Pong 5, just playing around with it trying to see what isn't working--adding/removing print statements, using VSCode's debug feature with a Lua debugger extention--so at this point there may well be a lot of bugs.
________________________________________________________________________________________________________
Inspired from what I found in HERE, I tried using
Code: Select all
require("filename")
Code: Select all
require "filename"
I tried dragging my Games Track folder onto the LOVE 11.3 and LOVE 10.2 icons, also, and it gave the same error. Colten's Pong distro folder works, though.