I can't figure out this lua error ("= expected") - possibly middleclass?
Posted: Wed Jun 20, 2018 2:00 am
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:
Here is the error in the love console:
Here is my code (not including middleclass library):
main.lua
bouncyBall.lua
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
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.
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'
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'
main.lua
Code: Select all
local class = require "middleclass"
require "bouncyBall"
function love.load()
math.randomseed(os.time())
local bounceSoundEffect = love.audio.newSource("bounceSoundEffect.wav", "static")
balls = {}
for i=1, 2000 do
local radius = math.random(5, 20)
local xPosition = math.random(radius, love.graphics.getWidth() - radius)
local yPosition = math.random(radius, love.graphics.getHeight() - radius)
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
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.radius = radius
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
love.graphics.circle("fill", self.position[1], self.position[2], self.radius)
else
love.graphics.rectangle("fill", self.position[1]-self.radius, self.position[2]-self.radius, self.radius*2, self.radius*2)
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
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
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.