This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Parzivail's profile picture

Modular Textbox System

Started by Parzivail, 05 January 2014 - 01:13 PM
Parzivail #1
Posted 05 January 2014 - 02:13 PM
This cool little utility allows you to put a text box wherever you want, you can specify the maximum length of the input, and you can set whether or not it is censored.

Pastebin:
http://pastebin.com/j9pYxix1



-- modular text box
term.clear()
function textbox(lineNumber,lineSpaces,length,protected)
term.setCursorPos(lineNumber,lineSpaces)
if protected then this="*" else this=nil end
input=read(this) -- get the input
if string.len(input) > length then
return string.sub(input, 1, length) -- return chars from 1 to length
else
return input -- returns the whole thing
end
end

Just pop in the function and you're good to go!

Tell me, should I make this an API? Would that be easier?

Plans:
Spoiler
  • Minimum Length
  • Colored BG

Comments and concerns appreciated!
H4X0RZ #2
Posted 05 January 2014 - 07:19 PM
You can shorten it for one line at the input = read part.

input=read(protected and '*' or nil)

Then you don't need the if statement.
Symmetryc #3
Posted 05 January 2014 - 07:51 PM
There are actually a couple of things you can shorten

term.clear()
function textbox(x, y, len, prot)
  term.setCursorPos(x, y)
  return read(prot and "*" or nil):sub(1, len)
end
Edited on 05 January 2014 - 06:51 PM