Jump to content




program syntax?


  • You cannot reply to this topic
3 replies to this topic

#1 YUGATUG

  • Members
  • 56 posts

Posted 28 March 2015 - 04:47 PM

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?

#2 HPWebcamAble

  • Members
  • 933 posts
  • LocationWeb Development

Posted 28 March 2015 - 05:45 PM

Do you mean the program will read text from a file?

To do that, you'll need the fs API


Oh, you meant capturing arguments when running the program, that explains a lot

Lyqyd covered it pretty well below

Edited by HPWebcamAble, 28 March 2015 - 09:23 PM.


#3 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

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:

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 YUGATUG

  • Members
  • 56 posts

Posted 29 March 2015 - 12:12 AM

Thanks! Great help!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users