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

Using program arguments to set variables

Started by metal249, 05 May 2013 - 02:24 AM
metal249 #1
Posted 05 May 2013 - 04:24 AM
Hello all, I have a question involving variables(I think). I'm trying to write a frame airship control program, so far, i can make it travel in one direction 10 blocks by running my program out to a wireless transmitter. I would like to set it up to travel any distance, without having to write a program for every distance. I would like to be able to type East 10 or East 100, and have it travel that far. Here is my program;

for i=1, 20, 1 do
output= "left"
redstone.setOutput(output, true)
sleep(.5)
redstone.setOutput(output, false)
sleep(.5)
end

Any help on this would be greatly appreciated!
Lyqyd #2
Posted 05 May 2013 - 12:19 PM
Split into new topic. A title was provided for you.
SadKingBilly #3
Posted 05 May 2013 - 01:01 PM

local tArgs = {...}
local distance = tArgs[1] or 1
local output = "left"
for i = 1, distance do
   redstone.setOutput(output, true)
   sleep(.5)
   redstone.setOutput(output, false)
   sleep(.5)
end
That will take the first argument passed to your program as the distance to travel. If no argument is passed, then it is defaulted to 1.