Trouble with Lua Love, Pong, and nil should be a number

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
autumn_colors
Prole
Posts: 2
Joined: Sun Jul 19, 2020 9:03 pm

Trouble with Lua Love, Pong, and nil should be a number

Post by autumn_colors »

--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--
pong.love
(15.12 KiB) Downloaded 140 times
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
(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

Code: Select all

require("filename")
instead of

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.
User avatar
pgimeno
Party member
Posts: 3686
Joined: Sun Oct 18, 2015 2:58 pm

Re: Trouble with Lua Love, Pong, and nil should be a number

Post by pgimeno »

Your class.lua is approximately the version from March 31, 2012 here:
https://github.com/vrld/hump/commits/master/class.lua

There have been quite some changes since then, including how the init constructor is handled.

Updating to the latest class.lua fixed it for me.
User avatar
zorg
Party member
Posts: 3470
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Trouble with Lua Love, Pong, and nil should be a number

Post by zorg »

Also, there's no functional difference between require("blah") and require "blah"; lua allows you to omit the function call's parentheses if it has one string or table value as parameter; foo "bar", foo 'bar', foo [[bar]]; foo {bar} all work.

make sure to use the newest push, as well.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
autumn_colors
Prole
Posts: 2
Joined: Sun Jul 19, 2020 9:03 pm

Re: Trouble with Lua Love, Pong, and nil should be a number

Post by autumn_colors »

Thank you zorg and pgimeno. I guess they removed the Karma part, or I'd +1 each of you. I finally got a response from cs50's discord page for this project--well, actually someone had posted an almost identical error half a day after I did, and the people who helped that person gave the fix.

Turns out, I needed an older version of push.lua (.3), and a version of class.lua that I couldn't seem to find through Google. Thanks for trying. And thanks for the clarification, zorg.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 4 guests