Jump to content




Text Input & Buttons!


  • You cannot reply to this topic
6 replies to this topic

#1 hbomb79

  • Members
  • 352 posts
  • LocationOrewa, New Zealand

Posted 18 September 2014 - 08:26 AM

How would I go about the following:

A setup page that asks you for an input, when entered you click a certain button which runs a function. the function obtains what you typed in the text box and then does what ever I choose (Not really important)


I want this:
- Page Opens
- Asks for input
- When finished imputing, click button and stores what was typed in a variable

Ive mucked around and got the buttons working... But the text box im not to sure about, I thought using parallel, but how would I get the input?

Edited by Hbomb_79, 18 September 2014 - 08:42 AM.


#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 18 September 2014 - 12:22 PM

I'd have a custom read function for the box running in parallel with the button, and when finished, dumps the input into a variable. Something like:
local input --#input box dumps the data into this variable
parallel.waitForAny( button, inputBox )

A suggestion: Have your inputBox function return when it receives a "return_input" event. Then have your button function do
os.queueEvent( "return_input" )
when clicked.

#3 hbomb79

  • Members
  • 352 posts
  • LocationOrewa, New Zealand

Posted 18 September 2014 - 08:43 PM

That's a good suggestion, but it's the custom read function I can't get my head around... How would I make it return when that event is queued?

#4 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 18 September 2014 - 11:24 PM

I don't happen to have a custom read for a input box lying around, I thought you had one... you could try and find one, I'm sure someone has posted one.

#5 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 19 September 2014 - 12:45 AM

Assuming your "read" function has a line like this somewhere:

if event == "key" and par1 == keys.enter then

... you'd change it to:

if (event == "key" and par1 == keys.enter) or event == "return_input" then

Using such an event may or may not be the best way to go about it, depending on the code you've got so far.

#6 hbomb79

  • Members
  • 352 posts
  • LocationOrewa, New Zealand

Posted 19 September 2014 - 04:20 AM

Well, I have no code so far... Ill try to think of something

#7 hbomb79

  • Members
  • 352 posts
  • LocationOrewa, New Zealand

Posted 19 September 2014 - 05:24 AM

Thanks Guys, Heres what I managed to get working, for anyone else interested:

Read Function:
function readN(len, replaceChar)
  submitted = false
  term.setTextColor(1)
  len = len or 10
  local input=""
  local key = 0
  term.setCursorBlink(true)
  repeat
	    event, p1, p2, p3 = os.pullEvent()
	    if event=="char" then
		  if #input < len then
   input = input .. p1
   term.write(replaceChar or p1)
		  end
	    elseif event=="key" and p1==keys.backspace and #input > 0 then
		  input = input:sub(1,#input-1)
		  local x,y = term.getCursorPos()
		  term.setCursorPos(x-1,y)
		  term.write(" ")
		  term.setCursorPos(x-1,y)
	    elseif event == "submit_Result" then --Button Event
   submitted = true
   return input
  elseif event == "mouse_click" then
   doClick('mouse_click', nil, p2, p3)
  end
  until submitted
end

Call Code:
input = readN(20)






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users