21 posts
Posted 27 February 2012 - 10:00 PM
This should be a simple question, but I didn't find the question anywhere.
How do I write a program that demands arguments?
Like, for example, excavate that prints "Usage: excavate <radius>" if you don't give it the radius when you start it.
473 posts
Location
Poland
Posted 27 February 2012 - 10:04 PM
use variablename={…} to get a table with every argument give to the program.
21 posts
Posted 27 February 2012 - 10:13 PM
Ah, thanks I got it to work.
18 posts
Location
My Computer. Possibly, my computer inside my computer.
Posted 27 February 2012 - 10:22 PM
EDIT:Ah, Ninja'd. :P/>/> To make a program
require a certain number of arguments, do something like this:
args = {...}
function printHelp()
print("Usage: MYProgram Arg1 Arg2 etc...")
end
argsReq = 2 --2 is an example, here.
if #args ~= argsReq then
return printHelp() -- When not in a function, return acts more like "quit"
-- but in the case of returning a function, it means "do this then quit".
end
--Continue program
To get arguments, type args[argNum]
EX: firstArg = args[1] would return "Test" if you ran "progName Test"
21 posts
Posted 28 February 2012 - 08:32 AM
Thanks you too :(/>/>
That's actually how I solved it.