Jump to content




Using program arguments to set variables


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

#1 metal249

  • New Members
  • 1 posts

Posted 05 May 2013 - 03: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!

#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 05 May 2013 - 11:19 AM

Split into new topic. A title was provided for you.

#3 SadKingBilly

  • Members
  • 160 posts

Posted 05 May 2013 - 12: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.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users