I just registered today, but I've been fiddling around with LÖVE and Lua this past week because I wanted to deliver an assignment using LÖVE, but I just found a dead end today.
A little background:
In a nutshell, I'm making a mini game for two players where P1 uses "Z" and P2 uses "M", and the one that presses their key the most wins the round, each player has three lifes. Each round is five seconds long, and after that, results get displayed for two seconds, and then it repeats until one of the players has 0 lifes.
One of the libraries I'm using is HUMP.Timer, but when the first timed function works, the one right after gets looped in delta time and stuck deleting lifes.
My pseudocode is something like this, I tried my best at making it short since the original code is in spanish at some parts:
Code: Select all
function love.update(dt)
if gamestate == "fight" then
checkLifes(p1Lifes,p2Lifes)
love.keypressed()
end
end
function love.draw()
if gamestate == "fight" then
drawthegui()
Timer.add(5, function() gamestate = "results" end)
elseif gamestate == "results" then
drawthegui()
winner = getWinner(p1Counter,p2Counter)
love.graphics.print (winner,300,300)
Timer.add(2, function() gamestate = "fight" end)
end
end
function love.keypressed(key)
if gamestate == "fight" then
if key == "z"
p1counter = p1counter + 1
elseif key == "m"
p2counter = p2counter + 1
elseif key == "q" then
love.event.push("quit")
end
end
end
function getWinner(p1Counter,p2Counter)
if p1Counter > p2Counter then
winner = "p1"
return winner
elseif p2Counter > p1Counter then
winner = "p2"
return winner
elseif p1Counter == p2Counter
winner = "tie"
return winner
end
end