Page 1 of 1

[SOLVED]Simple Countdown doesnt work.

Posted: Fri Feb 12, 2016 8:56 am
by W3LF
Hello everybody, I'm new to Lua programming.
I'm trying to work on a simple countdown, but Love gives me an error:
--
Error
Syntax Error: main.lua:16: 'then' expected near '='
--

here is my simple code:

function love.load()
love.graphics.setBackgroundColor(255, 255, 255)
totalTime = 30
gameOver = false
end

function love.update(dt)
totalTime = totalTime - dt
if totalTime <= 0 then
gameOver = true
end
end

function love.draw()
if gameOver = true then
love.graphics.print("GAME OVER", 100, 100)
end
end

I don't get why does Love tells that the syntax is wrong :/

Re: Simple Countdown doesnt work.

Posted: Fri Feb 12, 2016 8:58 am
by bartbes
Please use code tags next time, as it makes the code more readable (and preserves identation).
As for the issue, in love.draw your code says "if gameOver = true then", that should be ==, rather than =.

Re: Simple Countdown doesnt work.

Posted: Fri Feb 12, 2016 9:05 am
by W3LF
Uh, i'm so stupid.

Btw, I use tags, it's just Copy-Paste's effect, i'll be more careful next time :D

Re: Simple Countdown doesnt work.

Posted: Fri Feb 12, 2016 10:57 am
by zorg

Code: Select all

 These kind of tags: [code]
[/code]

Re: Simple Countdown doesnt work.

Posted: Fri Feb 12, 2016 11:49 pm
by Kasperelo

Code: Select all

if gameOver = true then
should be

Code: Select all

if gameOver == true then
-
Alternatively, you can simply write

Code: Select all

if gameOver then
which does the same thing

Re: Simple Countdown doesnt work.

Posted: Sat Feb 13, 2016 8:24 am
by W3LF
zorg wrote:

Code: Select all

 These kind of tags: [code]
[/code]
Oh, alright, sorry.