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

Input buffer

Started by Fish_tacoz, 15 March 2013 - 02:33 PM
Fish_tacoz #1
Posted 15 March 2013 - 03:33 PM
I wanted to make a system that could basically store your inputs, so for example, if you were to enter Fish then Tacoz, it would print Fish,Tacoz when I asked it to. Thanks for reading
AndreWalia #2
Posted 15 March 2013 - 08:28 PM
I will make this and teach you how this works
the code:
Spoiler
input = io.read()
print(input)
how this works:
Spoilerinput = io.read() returns what the player inputs because io.read() rio.read() gets the input from the player. print(input) works because lets say we entered "Lol wazzup"as our input. print(input) would then print "Lol wazzup"
XDaWNeDX #3
Posted 15 March 2013 - 08:31 PM
I will make this and teach you how this works
the code:
Spoiler
input = io.read()
print(input)
how this works:
Spoilerinput = io.read() returns what the player inputs because io.read() rio.read() gets the input from the player. print(input) works because lets say we entered "Lol wazzup"as our input. print(input) would then print "Lol wazzup"

He means so it can read multiple inputs, without any predetermined amount of inputs.

Simple arrays and loops, you should be able to figure it out yourself. :)/>
AndreWalia #4
Posted 15 March 2013 - 08:40 PM
If he means that then I would store the inputs in a table and the person would enter a number to get text
if you rly need help here is what i did
Spoiler
a = {}
while true do
  in = io.read()
  if not string.lower(in) == "stop" then
    a[#a+1] = in
    print(a[#a].." is now stored as "..#a)
  else
    break
  end
end
while true do
  print("enter the number the text you want to print is stored as")
  c = tonumber(io.read())
  if c >= 1 and c <= #a then
	print(a[c])
  else
	break
  end
end
Doyle3694 #5
Posted 15 March 2013 - 09:29 PM
Should be noted that read() also works, and the only real difference is that read() has more uses. io.read() is more of a "root function" and shall not be used in everyday simple programming.

For those geeks out there who wonder, io.read() does not support printed character replacement

Also, I do think 'in' would override a variable, 'for i in pairs() do'
Fish_tacoz #6
Posted 18 March 2013 - 12:34 PM
Hmm, well, I've set up something with fs.open which works, but is there a possibly better way to do this?
XDaWNeDX mentioned tables, but I'm not too sure what to do with those XP
AnDwHaT5 #7
Posted 18 March 2013 - 12:38 PM
this might help. http://www.computercraft.info/forums2/index.php?/topic/11156-get-variables-from-a-different-file-into-a-new-one-call-them/page__fromsearch__1
read all the comments
Kingdaro #8
Posted 18 March 2013 - 12:56 PM
If I understand you correctly, this should do what you want.


-- declare our table of words to print
local words = {}

while true do
  -- get words from the user
  write '> '
  local input = read()

  -- stop getting words if the user enters nothing
  if input == '' then break end

  -- if the user did enter something, throw it in our words table.
  table.insert(words, input)
end

-- dump all of the words to the console.
print(table.concat(words, ' '))

It keeps taking input from the user, then prints all of what you entered after you enter in nothing.
Fish_tacoz #9
Posted 20 March 2013 - 03:38 PM
ok, thanks everyone, got it resolved :)/>