quick & dirty code for easily getting text input

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
Dark Killer
Posts: 32
Joined: Tue Jan 25, 2005 3:10 am

quick & dirty code for easily getting text input

Post by Dark Killer »

Just some simple code to get user inputted text. Someone may find it usefull:

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&#40;a&#41;
		screen&#58;print&#40;118, 110, c..b, Color.new&#40;0,255,0&#41;&#41;
		pad = Controls.read&#40;&#41;
		if pad&#58;up&#40;&#41; then
			a=a+1
			Controls.waitpadup&#40;&#41;
		end	
		if pad&#58;down&#40;&#41; then
			a=a-1
			Controls.waitpadup&#40;&#41;
		end
		if pad&#58;cross&#40;&#41; then
			c=c..b
			Controls.waitpadup&#40;&#41;
		end
		if pad&#58;r&#40;&#41; then
			c=c.." "
			Controls.waitpadup&#40;&#41;
		end
		if pad&#58;l&#40;&#41; then
			c=string.sub&#40;c, 1, &#40;string.len&#40;c&#41;-1&#41;&#41;
			Controls.waitpadup&#40;&#41;
		end
		if pad&#58;start&#40;&#41; then
			screen&#58;print&#40;100, 140, "hello," .. c..b .. "!", Color.new&#40;255,0,0&#41;&#41;
			Controls.waitpadup&#40;&#41;
			screen.waitVblankStart&#40;&#41;
			screen.flip&#40;&#41;
			while true do
				screen.waitVblankStart&#40;&#41;
			end
		end
	screen.waitVblankStart&#40;&#41;
	screen.flip&#40;&#41;
	end
Mmy
Posts: 9
Joined: Mon Aug 08, 2005 2:53 am

Post by Mmy »

This is very intriguing, what i'd like to know is if there is a way to save the name to a file, .lua, .txt whatever. If there is, how does one go about doing it? (i have been unsuccesful in my searching of it.
officiallypoor
Posts: 8
Joined: Sat Sep 10, 2005 2:39 pm

Post by officiallypoor »

Yes how do we go about having a high score script with this text imput
Post Reply