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.