Hi! I'm trying to get a text field (read()) to have something already there before the user inputs any text. Does anyone know how to do this?
10 replies to this topic
#1
Posted 19 October 2012 - 11:07 PM
#2
Posted 19 October 2012 - 11:10 PM
modify the sLine variable at the top of the read function
#3
Posted 19 October 2012 - 11:12 PM
You can do
This has the side effect of the starting cursor in read still being after the first character
EDIT: It doesn't if you put os.queueEvent("key", keys["end"]) between where you queue the message and read()
os.queueEvent("char", "Starting text")
input = read()
EDIT: It doesn't if you put os.queueEvent("key", keys["end"]) between where you queue the message and read()
#4
Posted 19 October 2012 - 11:23 PM
You could first write something infront of it like so:
And for convenience sake you can put it into a function:
This way you can comfortably use textRead() whenever you want to write something before an input:
write("Enter Password: ")
local input = read()
And for convenience sake you can put it into a function:
local function textRead( text ) write( text ) return read() end
This way you can comfortably use textRead() whenever you want to write something before an input:
local pwd = textRead("Please Enter your Password: ")
#5
Posted 20 October 2012 - 02:56 AM
Well, here's what you might do:
I think the last line will work..
prevtext = "What's your name? | Answer: " write(prevtext) aftertext = read() aftertext = (prevtext..aftertext)
I think the last line will work..
#6
Posted 20 October 2012 - 03:33 AM
Well I wanted the text there that you can edit the existing text too.
#7
Posted 20 October 2012 - 04:46 AM
My suggestion will do that. It makes it so that read will pull the starting text queued as a char event and put it there before you start writing.
#8
Posted 20 October 2012 - 05:29 PM
faubiguy, on 20 October 2012 - 04:46 AM, said:
My suggestion will do that. It makes it so that read will pull the starting text queued as a char event and put it there before you start writing.
#9
Posted 20 October 2012 - 05:30 PM
Use os.queueEvent("key", keys["end"]) after queueing the message but before calling read()
#10
Posted 20 October 2012 - 05:47 PM
Why don't you just copy read and make your own function? It is open source in bios.lua. Should be trivial to prefill the character buffer.
Edit: as was suggested by pixeltoast.
Edit: as was suggested by pixeltoast.
#11
Posted 20 October 2012 - 11:22 PM
read() can be passed a history table. Passing a table containing the string and queuing an up-arrow key event may do what you wish. Copying read() and adding this (very simple) feature is certainly the best way to do this, though.
2 user(s) are reading this topic
0 members, 2 guests, 0 anonymous users











