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

read() improved. No longer replacing whole lines and you can now limit chars!

Started by libraryaddict, 11 April 2012 - 10:20 AM
libraryaddict #1
Posted 11 April 2012 - 12:20 PM
This is the read() but edited slightly.

Both of the read() now no longer replace the whole line on the screen.
So you can type in the middle of your sentance without destroying it! (Doesnt replace typed chars as I have no way to know what you overridden)

Added = read() readLimit()

read() is simply not replacing the whole string
readLimit(number) means the user can only input this many letters/numbers etc. As well as doesnt replace the whole string.

while true do
print("Write the 5 digit password to enter")
if string.len(API.readLimit(4)) == 5 then
opendoor()
sleep(5)
shell.run("clear")
end
end

Or maybe you want to limit names people choose? Or passwords?
Anyways. read() is good for typing into that fancy screen of yours without making it look terrible after the first keystroke.

http://pastebin.com/j988HWEG
Mads #2
Posted 12 April 2012 - 03:19 PM
Why do you use API.readLimit(4) when it is supposed to be 5?
libraryaddict #3
Posted 14 April 2012 - 03:35 AM
The point of the example code I did was to say "If you auctally got this. Then you get in. But you aint gonna get this. So you aint gonna get in"
libraryaddict #4
Posted 11 June 2012 - 07:48 AM
bump
Bossman201 #5
Posted 14 June 2012 - 04:02 AM
Nice idea. I didn't get it at first, but now I do. Although you could just do something like:
local input = {}
local charNum = 1

function decode(array)
 for i = 1, charNum do
  string = string .. array[i]
 end
 return string
end

while true do
 evt, char = os.pullEvent()
 input[charNum] = char
 charNum = charNum + 1
end

message = decode(input)

EDIT: Tried to do a mathematical operator on a string instead of concatenation. It's late.
libraryaddict #6
Posted 14 June 2012 - 12:34 PM
Pity I do not seem to understand you very well.