[SOLVED]Simple Countdown doesnt work.

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
W3LF
Prole
Posts: 8
Joined: Fri Feb 12, 2016 7:40 am

[SOLVED]Simple Countdown doesnt work.

Post 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 :/
Last edited by W3LF on Sat Feb 13, 2016 8:29 am, edited 1 time in total.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Simple Countdown doesnt work.

Post 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 =.
W3LF
Prole
Posts: 8
Joined: Fri Feb 12, 2016 7:40 am

Re: Simple Countdown doesnt work.

Post 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
User avatar
zorg
Party member
Posts: 3468
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Simple Countdown doesnt work.

Post by zorg »

Code: Select all

 These kind of tags: [code]
[/code]
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
Kasperelo
Party member
Posts: 343
Joined: Fri Apr 13, 2012 1:47 pm
Location: The Milky Way

Re: Simple Countdown doesnt work.

Post 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
W3LF
Prole
Posts: 8
Joined: Fri Feb 12, 2016 7:40 am

Re: Simple Countdown doesnt work.

Post by W3LF »

zorg wrote:

Code: Select all

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

Who is online

Users browsing this forum: Bing [Bot] and 5 guests