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

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
gabberswag
Prole
Posts: 4
Joined: Fri Aug 12, 2016 10:34 am

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

Post 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.
User avatar
slime
Solid Snayke
Posts: 3159
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

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

Post by slime »

You can use [wiki]love.keyboard.setTextInput[/wiki] to enable or disable text input (it's enabled by default on desktop systems).
raz87
Prole
Posts: 7
Joined: Fri Jul 08, 2016 8:22 am

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

Post 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 :-)
gabberswag
Prole
Posts: 4
Joined: Fri Aug 12, 2016 10:34 am

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

Post by gabberswag »

gonna use both options just in case

thanks guys
Post Reply

Who is online

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