function love.draw()
if mode == point then
-- draw all four corners of the first square
love.graphics.points( square1[1] )
love.graphics.points( square1[2] )
love.graphics.points( square1[3] )
love.graphics.points( square1[4] )
end
end
Which runs just fine when mode is set to point. The problem is that it also runs when it's set to ANYTHING else. Did I mess up the if statement? Am I stupid? Is Lua stupid? Is LÖVE stupid?
function love.load()
mode = nil
-- ...
end
function love.draw()
if mode == nil then
-- because mode IS nil, this will be run every time love.draw is called
end
end
Lua treats undeclared variables as globals with the value of nil (signifying the absence of a value), so you need to assign said "line" and "point" variables an actual value prior assigning them to "mode". As such, I believe maybe you intended was something like this?
function love.load()
line = "line" -- note the quotes; this makes it so we're assigning a string of value "line" to the variable
-- we could assign anything else, like a number, so long the variables line and point do not share the same value
point = "point"
mode = line
-- ...
end
function love.draw()
if mode == point then
-- because mode's value is "line" and not "point", this code is not run
end
end
You can read more about lua's types and values from lua pil.
Otherwise, you can just put single or double quotes around point and line in love.draw, if you, you know, don't want to treat those as variables, but literal strings; this goes for love.load as well, since you're setting mode to the undefined variable line:
function love.load()
mode = 'line'
end
function love.draw()
if mode == 'point' then
-- runs if mode is the string 'point'
elseif mode == "line" then
-- runs if mode is the string "line"
end
end
Me and my stuff True 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.