115 posts
Posted 20 April 2015 - 04:21 PM
Hello again. I'm trying to make a program that takes an input from the terminal. For example:
Hello would be the name of the program
If I type in:
"Hello 10"
It would print "Hello World" 10 times.
If I type in:
"Hello 1100"
It would print "Hello World" 1100 times.
Is it like a = args[]?
3057 posts
Location
United States of America
Posted 20 April 2015 - 04:30 PM
local tArgs = { ... }
…will give you a table that looks something like this:
local tArgs = {
"10",
}
In addition to usage in programs, it can be used in function declared like this:
local function t( ... )
--#stuff
end
local t = function( ... )
--#stuff
end
Edited on 20 April 2015 - 02:31 PM
2427 posts
Location
UK
Posted 20 April 2015 - 04:32 PM
Is it like a = args[]?
close.
args = {…}
or
anyVariableName = {…}
although args is the convention
you can access them like so:
if you typed in "hello 10"
args[1] would equal 10
if you typed in "program this is a test"
args[1] would be "this"
args[2] would be "is"
args[3] would be "a"
args[4] would be "test"
Edited on 20 April 2015 - 02:32 PM
115 posts
Posted 20 April 2015 - 04:42 PM
local tArgs = { ... }
…will give you a table that looks something like this:
local tArgs = {
"10",
}
In addition to usage in programs, it can be used in function declared like this:
local function t( ... )
--#stuff
end
local t = function( ... )
--#stuff
end
Thanks!! :D/>
115 posts
Posted 20 April 2015 - 05:27 PM
New problem:
How to I turn L3 = {"H", "i", "t", "h", "e", "r", "e"} into a string?
Example:
L4 = "lol"
L3 = {"H", "i", "t", "h", "e", "r", "e"}
– CODE HERE to make L3 become L4–
print(L4)
– it would print "Hithere"
2427 posts
Location
UK
Posted 20 April 2015 - 05:36 PM
concatenate the strings
chars = {"t","e","s","t"}
string = "" --this is required else you may have a mess at the front of your string
for i = 1, #chars do --I should have started at 1 not 0
string = string..chars[i]
end
Edited on 20 April 2015 - 03:42 PM
115 posts
Posted 20 April 2015 - 05:39 PM
Thanks.
2427 posts
Location
UK
Posted 20 April 2015 - 05:41 PM
i just patched a bug in my string concatenation code, you may want to check yours
Edited on 20 April 2015 - 03:43 PM
8543 posts
Posted 20 April 2015 - 05:46 PM
You could use table.concat instead.
2427 posts
Location
UK
Posted 20 April 2015 - 05:55 PM
You could use table.concat instead.
didn't know that that existed
2679 posts
Location
You will never find me, muhahahahahaha
Posted 20 April 2015 - 06:10 PM
Now you do ;)/>