Help with textinput and numbers
Posted: Sun Oct 02, 2016 12:24 am
Hi
I'm new to LÖVE and to programming, so I have a lot of newbie questions. My first question is about textinput. I want to get a number from user and make some comparisons with it (greater, etc). But it does not work as expected. Maybe I have to convert the string into int before making the comparisons?
Regards
Ernesto
I'm new to LÖVE and to programming, so I have a lot of newbie questions. My first question is about textinput. I want to get a number from user and make some comparisons with it (greater, etc). But it does not work as expected. Maybe I have to convert the string into int before making the comparisons?
Regards
Ernesto
Code: Select all
function love.load()
pregunta = "Guess the number:"
text = ""
gane = false
pistamayor = "A hint: it is greater."
pistamenor = "A hint: it is lesser."
pista = " "
end
function love.textinput(t)
text = text..t
end
function love.update(dt)
if love.keyboard.isDown('escape') then
love.event.push('quit')
end
if love.keyboard.isDown('return') then
if text == "40" then
pregunta = "¡Well done!"
pista = " "
gane = true
end
if text > "40" then
pista = pistamenor
end
if text < "40" then
pista = pistamayor
end
text = ""
end
end
function love.draw()
love.graphics.printf(pregunta, 0, 0, love.graphics.getWidth())
if gane == false then
love.graphics.printf(text, 0, 20, love.graphics.getWidth())
end
love.graphics.printf(pista, 0, 30, love.graphics.getWidth())
end