259 posts
Posted 29 December 2012 - 07:36 PM
I have been trying to figure out how Dan200 made the tunnel program where in the directory, you can type in the desired program, and then a number (still in the directory) and then run that program using that number in the program. I have been instead running the program then have it ask how many times to run. I'd like to be able to be able to do stay in the directory and type "staircase x" where x=read() but I can't figure it out. any help would be much appreciated! :D/>
1111 posts
Location
Portland OR
Posted 29 December 2012 - 08:16 PM
Read up on using arguments.
Briefly the program will capture the arguments into a table called tArgs{} so you will need to declare that at the start of your program. Then anywhere that you would have used the x from the read() you will want to use the data from the table instead. Here is a short example to get you started.
local tArgs = {...} -- to accept any number of arguments
--do some error checking
if #tArgs < 1 then -- if no args sent(can adjust this to be more specific to your program)
error("Usage: staircase x")
end
--the data will be stored using standard indicies so it will start with 1
x = tArgs[1] -- to replace the read
2005 posts
Posted 29 December 2012 - 08:23 PM
local tArgs = { ... }
x = tArgs[1]
y = tArgs[2]
z = tArgs[3]
Note that the command line parameters are always passed as strings, if you need them to be numbers you must tonumber them.