I can't figure out this lua error ("= expected") - possibly middleclass?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
harrison
Prole
Posts: 16
Joined: Tue Feb 03, 2015 5:24 am

I can't figure out this lua error ("= expected") - possibly middleclass?

I made a mistake with my lua coding while I was updating my program and now it won't launch anymore for some reason.

When I try to launch the program, it throws this error:

Code: Select all

Error
Syntax error: main.lua:1: '=' expected
Traceback
[C]: at 0x7ffe06762f00
[C]: in function 'require'
[C]: in function 'xpcall'
[C]: in function 'xpcall'
Here is the error in the love console:

Code: Select all

Error: Syntax error: main.lua:1: '=' expected

stack traceback:
[string "boot.lua"]:637: in function <[string "boot.lua"]:633>
[C]: at 0x7ffe06762f00
[C]: in function 'require'
[string "boot.lua"]:475: in function <[string "boot.lua"]:311>
[C]: in function 'xpcall'
[string "boot.lua"]:645: in function <[string "boot.lua"]:639>
[C]: in function 'xpcall'
Here is my code (not including middleclass library):

main.lua

Code: Select all

local class = require "middleclass"
require "bouncyBall"

math.randomseed(os.time())
local bounceSoundEffect = love.audio.newSource("bounceSoundEffect.wav", "static")
balls = {}
for i=1, 2000 do
local color = {math.random(), math.random(), math.random()}
local xVelocity = math.random(-50, 50)
local yVelocity = math.random(-50, 50)
print(color[1], color[2], color[3])
balls[#balls+1] = bouncyBall:new(xPosition, yPosition, radius, xVelocity, yVelocity, color, bounceSoundEffect:clone())
end
end

function love.draw()
for index, value in ipairs(balls) do
value:draw()
end
end

function love.update()
for i=1, #balls do
balls[i]:update()
end
end
bouncyBall.lua

Code: Select all

local class = require "middleclass"
bouncyBall = class("bouncyBall")

function bouncyBall:initialize(xPosition, yPosition, radius, xVelocity, yVelocity, color, bounceSoundEffect)
self.position = {xPosition,yPosition}
self.velocity = {xVelocity, yVelocity}
self.color = color
self.bounceSoundEffect = bounceSoundEffect
end

function bouncyBall:draw()
love.graphics.setColor(self.color[1], self.color[2], self.color[3])
if math.random(0,1) == 1 then
else
end
end

function bouncyBall:update()
self:calculateCollisions()
self:move()
end

function bouncyBall:calculateCollisions()
local collision = false
if(self.position[1] + self.radius >= love.graphics.getWidth() or self.position[1] - self.radius <= 0) then
self.velocity[1] = -self.velocity[1]
collision = true
end

if(self.position[2] + self.radius >= love.graphics.getHeight() or self.position[2] - self.radius <= 0) then
self.velocity[2] = -self.velocity[2]
collision = true
end

if collision then
self:bounceSound()
end
end

function bouncyBall:move()
self.position[1] = self.position[1] + self.velocity[1]
self.position[2] = self.position[2] + self.velocity[2]
end

function bouncyBall:bounceSound()
self.bounceSoundEffect:play()
end
The code fails before the program launches, otherwise I would try print() debugging. There should only be one bug, but I can't find it. I tried deleting massive portions of my code to narrow down the location of the bug, but was never able to get it to go away (or even change lines) for some reason. I think the bug might be related to me misusing middleclass somehow, which would explain why the console error message doesn't help at all.

Does anybody have any idea what is wrong with my code?
In the future, is there any debugging tool/techniques I should use to find bugs like these?

.love file
sampleProgram.love

Also, critique of my code is welcome - I am trying to improve the neatness of my code, so if you see any bad coding style please let me know.

DanielPower
Citizen
Posts: 50
Joined: Wed Apr 29, 2015 5:28 pm

Re: I can't figure out this lua error ("= expected") - possibly middleclass?

What text editor are you using? When I tried to open main.lua, here's how it appeared in both Atom and micro.

The other files appear normal. Only main.lua is like this. If I replace main.lua with the text you included in your post, it just works. I think your main.lua file got corrupted somehow. The code is fine.

harrison
Prole
Posts: 16
Joined: Tue Feb 03, 2015 5:24 am

Re: I can't figure out this lua error ("= expected") - possibly middleclass?

Thank you so much, I re-made the file and it works now
The file must have gotten corrupted but the corruption didn't show up in notepad++ or even notepad somehow.
I am currently using Notepad++ as my editor. What program do you use?

zorg
Party member
Posts: 2732
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: I can't figure out this lua error ("= expected") - possibly middleclass?

harrison wrote:
Wed Jun 20, 2018 3:49 am
Thank you so much, I re-made the file and it works now
The file must have gotten corrupted but the corruption didn't show up in notepad++ or even notepad somehow.
I am currently using Notepad++ as my editor. What program do you use?
He uses either Atom, micro, or both, as he said.
Also, most code editors allow you to set an encoding for the file to use, and to save it with; i know Np++ supports a literal ton of them; be sure to save the file with UTF-8 (without a Byte-Order Mark (BOM))
Me and my stuff True 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.

harrison
Prole
Posts: 16
Joined: Tue Feb 03, 2015 5:24 am

Re: I can't figure out this lua error ("= expected") - possibly middleclass?

whoops, I missed that in my excitement. Thanks for the help guys.

Who is online

Users browsing this forum: Google [Bot] and 8 guests