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

Io.read() help

Started by MechanicalMorgan, 16 December 2017 - 09:46 AM
MechanicalMorgan #1
Posted 16 December 2017 - 10:46 AM
I'm trying to figure out a way to make seperate variables from one io.read(). Here is an example of what I want it to produce.
User input: Hello world
Var1: Hello
Var2: World

Is this possible? if so, what code is needed?

Thanks!

Morgan
Lupus590 #2
Posted 17 December 2017 - 01:40 PM
http://lua-users.org/wiki/SplitJoin
MechanicalMorgan #3
Posted 17 December 2017 - 07:45 PM
I'm still very new to Lua, So, could you help me with the specifics of what I'm looking for?
Bomb Bloke #4
Posted 18 December 2017 - 12:01 AM
The section on splitting strings, specifically. You'll also want to read up on tables if you're not already familiar with them.
Zetrious #5
Posted 24 December 2017 - 02:02 PM
I'll spoon feed you.


local words = {};
io.write("Enter Stuff: ");
local r = io.read()
for i in string.gmatch(r,"[^ ^]+") do
table.insert(words, i)
end
for i,v in pairs(words) do
print(v)
end