This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
bscross32's profile picture

[Lua] How do I write a program that takes an argument from me at runtime.

Started by bscross32, 19 September 2012 - 04:32 PM
bscross32 #1
Posted 19 September 2012 - 06:32 PM
Hello all, heres what I'm trying to do. I want to write a program that takes its arguments from me as I start it. An example would be Direwolf's stair stepping turtle where he could pass the Y coordinate like this

stairs 55
The turtle would dig stairs to Y 55. It would be more streamline if I could figure this out. I've written functions that get their arguments from me after prompting or from another place inside the main function. I've seen his code and don't know how he does it.

Thanks for any help on this. –Brandon

Thanks GopherAtl, I'll try it out.
GopherAtl #2
Posted 19 September 2012 - 07:09 PM
the parameters to a program are stored as strings in the magic word "…" (without the quotes). Put "local args={…}" at the start and you can access them as args[1], args[2], etc. They're always strings, so if you need a number, you'll have to do "tonumber(args[1])"

is this in the faq yet? if not it should be.