Code: Select all
--Quick and dirty LUA text input example
--by: Dark Killer
--You are free to modify and/or implement this in your own projects, all I ask in return is that you credit me.
--Controls:
-- Up/Down: select character
-- X: add character
-- R: space
-- L: backspace
-- Start: submit
function Controls.waitpadup() --pauses execution untill all buttons are released
pad=Controls.read()
while pad:select() or pad:start() or pad:up() or pad:right() or pad:down() or pad:left() or pad:l() or pad:r() or pad:triangle() or pad:circle() or pad:cross() or pad:square() do
screen.waitVblankStart()
pad=Controls.read()
end
end
a=65
c=""
while true do
screen:clear(Color.new(0,0,0))
screen:print(100, 100, "what is your name?", Color.new(0,255,0))
if a<65 then
a=90
end
if a>90 then
a=65
end
b=string.char(a)
screen:print(118, 110, c..b, Color.new(0,255,0))
pad = Controls.read()
if pad:up() then
a=a+1
Controls.waitpadup()
end
if pad:down() then
a=a-1
Controls.waitpadup()
end
if pad:cross() then
c=c..b
Controls.waitpadup()
end
if pad:r() then
c=c.." "
Controls.waitpadup()
end
if pad:l() then
c=string.sub(c, 1, (string.len(c)-1))
Controls.waitpadup()
end
if pad:start() then
screen:print(100, 140, "hello," .. c..b .. "!", Color.new(255,0,0))
Controls.waitpadup()
screen.waitVblankStart()
screen.flip()
while true do
screen.waitVblankStart()
end
end
screen.waitVblankStart()
screen.flip()
end