10 posts
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
290 posts
Location
St.Louis, MO
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:
Spoiler
input = 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"
8 posts
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:
Spoiler
input = 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. :)/>
290 posts
Location
St.Louis, MO
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
818 posts
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'
10 posts
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
259 posts
Posted 18 March 2013 - 12:38 PM
1688 posts
Location
'MURICA
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.
10 posts
Posted 20 March 2013 - 03:38 PM
ok, thanks everyone, got it resolved :)/>