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

Computercraft [1.33] [lua] [question] Usages

Started by Rapidfire52, 23 May 2012 - 11:08 PM
Rapidfire52 #1
Posted 24 May 2012 - 01:08 AM
[Computercraft] [1.33] [lua] [question] "Usages"

Excuse me if im asking too many things but im fairly new to programming.
In certain programs there will be Usages messages
For EX:
if you type "move"
it will say
Usages: "move <target> <destination>"
I was wondering the coding for this
i have a small factory with another mod and i need coolant for it
whenever u type coolant, i had it said "Turn on or off?"
but thats just annoying.
i got it to the point where if u typed coolant off (for example) it would say "usages <on or off>,
but i would need to type coolant off AGAIN for it to actually work.
im wondering how to get it to work if i JUST have to type "coolant on" or "coolant off" once and have it work
Without having to make multiple programs for it.
so i want the result to be
If they type "coolant" it would say "Usages: coolant <on or off>"
if they type "coolant on" (WITHOUT TYPING "coolant" FIRST) it would turn a redstone signal on
if they type "coolant off" WITHOUT TYPING "coolant" FIRST) it would turn off a redstone signal
————————————————————————————————————————
I KNOW it is NOT correct, (probably not even close)
but this is what i have currently:
————————————————————————————————————————
print "Usage:"
print "coolant <ON or OFF>"
input = read()
if "coolant on" == input then
print "Coolant turned on!"
redstone.setOutput("back",true)
elseif "coolant off" == input then
print "Coolant turned off!"
redstone.setOutput("back",false)
else
print "Try again!"
end
————————————————————————————————————————-

Thanks for the help, these forums have active admins and i appreciate that.

Thanks,
Rapidfire52
Lyqyd #2
Posted 24 May 2012 - 02:23 AM
At the top of your program:


tArgs = {...}
--Grab the arguments passes to the program in this table
if #tArgs ~= 1 or (tArgs[1] ~= "on" and tArgs[1] ~= "off") then
    print("Usage: coolant <on|off>")
elseif tArgs[1] == "on" then
    --Turn it on
else
    --Turn it off
end