These buttons execute the same callback but they are different tables!

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.
User avatar
BrotSagtMist
Party member
Posts: 604
Joined: Fri Aug 06, 2021 10:30 pm

Re: These buttons execute the same callback but they are different tables!

Post by BrotSagtMist »

Actually take the whole example:

Code: Select all

utf8=require("utf8")
Line="1234567890"
Pos=3
Font=love.graphics.newFont()
A,B=string.match(Line, "("..utf8.charpattern:rep(Pos)..")(.*)")
function love.keypressed(k)
 if k =="backspace" then Delete() 
 elseif k== "right" then 
  Pos=Pos+1
  A,B=string.match(Line, "("..utf8.charpattern:rep(Pos)..")(.*)")
 elseif k== "left" then 
  Pos=Pos-1
  A,B=string.match(Line, "("..utf8.charpattern:rep(Pos)..")(.*)")
 end
end
function love.textinput(k)
  Pos=Pos+1
  A,B=string.match(Line, "("..utf8.charpattern:rep(Pos-1)..")(.*)")
  A=A..k
  Line=A.. (B or "")
end
function Delete()
 A,_,B=string.match(Line, "("..utf8.charpattern:rep(Pos-1)..")("..utf8.charpattern..")(.*)")  
 Line=A..(B or "")
 Pos=Pos-1
end
function love.draw()
 love.graphics.print(Line)
 love.graphics.print("|", Pos~=0 and Font:getWidth(A) or nil)  
end
There are a ton of exceptions to add that makes coding a good text input painfully boring tho.
obey
Post Reply

Who is online

Users browsing this forum: No registered users and 20 guests