Miscellaneous Bug
Posted: Sat Apr 06, 2013 10:46 pm
I have 156 lines of code in the buggy class alone, one bug, but I have not got a clue why
Also I think my code is inefficient/resource intensive
I don't know how you guys can help me.
Here is the code for the buggy class:
And this is the bug: "Syntax error: class/menu.lua: 51: function arguments expected near 'elseif' "
Much thanks in advance, Kyle.
![Sad :(](./images/smilies/ms-sad.png)
![Sad :(](./images/smilies/ms-sad.png)
Here is the code for the buggy class:
Code: Select all
menu = {}
menu.__index = menu
function menu.create()
local mnu = {}
setmetatable(mnu,menu)
mnu.open = true
mnu.font30 = love.graphics.newImageFont("font/font30.png", " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?-+/():;%&`'*#=[]\"")
mnu.mute = love.graphics.newImage("font/mute.png")
mnu.n_mute = love.graphics.newQuad(0, 0, 12, 18, 18, 18)
mnu.alpha = {0, 0, 0}
mnu.starttype = "Start"
mnu.menutype = "Dodge Ballz"
mnu.bg_song = love.audio.newSource("sound/primetime.mp3", "stream")
mnu.bg_song:setLooping(true)
mnu.bg_song:setVolume(0.25)
mnu.bg_song:play()
mnu.select = love.audio.newSource("sound/select.wav", "static")
mnu.end_s = love.audio.newSource("sound/end.wav", "static")
mnu.sndTime = 0
mnu.mute = love.graphics.newImage("font/mute.png")
mnu.n_mute = love.graphics.newQuad(0, 0, 11, 18, 18, 18)
mnu.vol_width = 400
return mnu
end
function menu:draw()
--Set background rectangles
love.graphics.setColor(224, 27, 150, 100)
love.graphics.rectangle("fill", 0, 0, width, height)
love.graphics.setColor(255, 255, 255, self.alpha[1])
love.graphics.rectangle("fill", 0, height/2 - 95, width, 43)
love.graphics.setColor(255, 255, 255, self.alpha[2])
love.graphics.rectangle("fill", 0, height/2 -45, width, 43)
love.graphics.setColor(255, 255, 255, self.alpha[3])
love.graphics.rectangle("fill", 0, height/2 + 5, width, 43)
love.graphics.setColor(255, 255, 255, 255)
love.graphics.rectangle("fill", width/2 - 200, height/2 + 5, self.vol_width, 43)
--Draw text
love.graphics.setColor(255, 255, 255, 255)
love.graphics.setFont(font80)
love.graphics.printf(self.menutype, 0, height/2 - 300, width, "center")
love.graphics.setFont(self.font30)
love.graphics.printf(self.starttype, 0, height/2 - 100, width, "center")
love.graphics.printf("Quit", 0, height/2 - 50, width, "center")
love.graphics.printf("Volume", 0, height/2, width, "center")
end
function menu:update(dt)
if self:checkHov(height/2 - 95, 1, dt) then
self:play_b
elseif self:checkHov(height/2 - 45, 2, dt) then
love.event.quit()
elseif self:checkHov(height/2 + 5, 3, dt) then
self:vol_change(love.mouse.getX(), love.mouse.getY())
end
end
function menu:keyPress(k)
if k == "escape" then
if started then
if self.open then
self.open = false
love.mouse.setVisible(false)
love.mouse.setGrab(true)
self.bg_song:setVolume(1.0)
else
love.mouse.setVisible(true)
love.mouse.setGrab(false)
self.open = true
self.bg_song:setVolume(0.25)
end
else
love.event.quit()
end
end
end
function menu:checkHov(y, num, dt)
if love.mouse.getY() >= y and y + 43 > love.mouse.getY() then
self.alpha[num] = self.alpha[num] - ((self.alpha[num] - 100) * dt * 2)
if love.mouse.isDown("l") then
return true
else
return false
end
else
self.alpha[num] = self.alpha[num] - ((self.alpha[num] + 100) * dt * 2)
end
if self.alpha[num] > 99 then
self.alpha[num] = 100
elseif self.alpha[num] < 1 then
self.alpha[num] = 0
end
end
function menu:play_b
self:playSound(self.select)
self.open = false
love.mouse.setVisible(false)
love.mouse.setGrab(true)
self.bg_song:setVolume(1.0)
charK = character:create()
if endStatus then
score = 0
speed = 0.12
spawnamount = 1
enemyList = {}
endStatus = false
spawntime = love.timer.getMicroTime()
speedtime = love.timer.getMicroTime()
self.starttype = "Start"
self.menutype = "Dodge Ballz"
end
if not started then
self.menutype = "Pause"
self.starttype = "Continue"
started = true
spawntime = love.timer.getMicroTime()
end
end
function menu:finish()
self.end_s:play()
self.open = true
self.menutype = "Game Over"
self.starttype = "Restart"
started = false
love.mouse.setVisible(true)
love.mouse.setGrab(false)
self.bg_song:setVolume(self.vol_width/40 - 0.75)
charK = nil
end
function menu:playSound(snd)
if love.timer.getMicroTime() - self.sndTime > 0.425 then
snd:stop()
snd:play()
self.sndTime = love.timer.getMicroTime()
end
end
function menu:vol_change(x, y)
if x > width/2 - 200 and x < width/2 and y > height/2 + 5 and y < height/2 + 48 then
self.vol_width = ((width/2 - x) * -1) + 200
self.bg_song:resume()
if self.vol_width < 5 then
self.vol_width = 0
self.bg_song:pause()
end
love.audio.setVolume(self.vol_width/400)
elseif x > width/2 and x < width/2 + 200 and y > height/2 + 5 and y < height/2 + 48 then
self.vol_width = (x - width/2) + 200
love.audio.setVolume(self.vol_width/400)
end
end
Much thanks in advance, Kyle.