I want to create a program that will read the text after the program name, so something like this: 'Enderchest List' that will list all the ender chests i have from Ender Storage. How do i make my program find key words after the program name?
program syntax?
Started by YUGATUG, Mar 28 2015 04:47 PM
3 replies to this topic
#1
Posted 28 March 2015 - 04:47 PM
#3
Posted 28 March 2015 - 06:14 PM
I think he means that he wants to use command-line arguments to change the behavior of his program. To do so, you need to capture the arguments the shell passes in to your program:
Notice that we captured the arguments into a table. The shell will split up the string you used to run the program, with space characters as the separator. So, in your example, "enderchest list", the shell would send a table containing "list" at index 1. So to compare against the first argument, you would do something like this:
local args = {...}
Notice that we captured the arguments into a table. The shell will split up the string you used to run the program, with space characters as the separator. So, in your example, "enderchest list", the shell would send a table containing "list" at index 1. So to compare against the first argument, you would do something like this:
local args = {...}
if args[1] == "list" then
listEnderChests()
end
#4
Posted 29 March 2015 - 12:12 AM
Thanks! Great help!
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











