Page 1 of 1

love.textinput() reads input that "activates" it

Posted: Fri Aug 12, 2016 10:45 am
by gabberswag
hey

Im trying to make my game have you input name after you picked one of options using a-z keys, however the key used to pick the option also gets carried on to the next screen as the first letter of name.

Code: Select all

function love.load()
	text = ""
	inputReady = false
end
 
function love.textinput(t)
if inputReady then
	text = text .. t
end
end
 
function love.draw()
if inputReady then
    love.graphics.print(text, 0, 0)
else love.graphics.print("press a to start typing",0,0) end
end

function love.keypressed(key)
if inputReady then
if key == "backspace" then text = string.sub(text,1,string.len(text)-1) 
end
elseif key == "a" then inputReady = true 
end
end
This code is roughly what i have so far, and ive sure tried a plethora of different workarounds so far, but they all didnt change anything.

Re: love.textinput() reads input that "activates" it

Posted: Fri Aug 12, 2016 4:29 pm
by slime
You can use [wiki]love.keyboard.setTextInput[/wiki] to enable or disable text input (it's enabled by default on desktop systems).

Re: love.textinput() reads input that "activates" it

Posted: Fri Aug 12, 2016 4:31 pm
by raz87
Hey man, try this. Instead of keypressed, use keyreleased:

Code: Select all

function love.load()
   text = ""
   inputReady = false
end
 
function love.textinput(t)
  if inputReady then
     text = text .. t
  end
end
 
function love.draw()
  if inputReady then
      love.graphics.print(text, 0, 0)
  else 
    love.graphics.print("press a to start typing",0,0) 
  end
end

function love.keyreleased(key)
  if inputReady then
    if key == "backspace" then 
      text = string.sub(text,1,string.len(text)-1) 
    end
  elseif key == "a" then 
    inputReady = true 
  end
end
Hope this helps :-)

Re: love.textinput() reads input that "activates" it

Posted: Fri Aug 12, 2016 8:17 pm
by gabberswag
gonna use both options just in case

thanks guys