Jump to content




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


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

#1 libraryaddict

  • New Members
  • 195 posts

Posted 11 April 2012 - 11:20 AM

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

#2 Mads

  • Members
  • 604 posts
  • LocationCopenhagen, Denmark

Posted 12 April 2012 - 02:19 PM

Why do you use API.readLimit(4) when it is supposed to be 5?

#3 libraryaddict

  • New Members
  • 195 posts

Posted 14 April 2012 - 02: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"

#4 libraryaddict

  • New Members
  • 195 posts

Posted 11 June 2012 - 06:48 AM

bump

#5 Bossman201

  • New Members
  • 92 posts

Posted 14 June 2012 - 03: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.

#6 libraryaddict

  • New Members
  • 195 posts

Posted 14 June 2012 - 11:34 AM

Pity I do not seem to understand you very well.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users