Guest User

move

a guest
Jan 4th, 2013
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.12 KB | None | 0 0
  1. local programPath="frameengine/move"
  2. local args={...}
  3. local runningProgram=shell.getRunningProgram()
  4. local transmitter
  5. local trasmitterSide
  6. local intervalBetweenPulses=1.5
  7.  
  8. local frequencies={
  9.   north=3401,
  10.   east=3402,
  11.   south=3403,
  12.   west=3404,
  13.   up=3405,
  14.   down=3406
  15. }
  16.  
  17. -- initialize the wireless transmitter
  18. for i, side in pairs(redstone.getSides()) do
  19.   if peripheral.getType(side)=="wireless-transmitter" then
  20.     transmitter=peripheral.wrap(side)
  21.     trasmitterSide=side
  22.   end
  23. end
  24.  
  25. if transmitter==nil then
  26.   print("No wireless transmitter found!")
  27.   return
  28. end
  29.  
  30. function pulse(frequency)
  31.   transmitter.setFreq(frequency)
  32.   redstone.setOutput(trasmitterSide, true)
  33.   sleep(0.1)
  34.   redstone.setOutput(trasmitterSide, false)
  35. end
  36.  
  37. function move(direction, count)
  38.   for i=1, count*2 do
  39.     pulse(frequencies[direction])
  40.     sleep(intervalBetweenPulses)
  41.   end
  42. end
  43.  
  44. function runMoveCommand()
  45.   if #args==2 then
  46.     move(args[1], tonumber(args[2]))
  47.   else
  48.     print("move [north/south/west/east/up/down] [number of blocks]")
  49.   end
  50. end
  51.  
  52. if runningProgram==programPath then
  53.   runMoveCommand()
  54. end
Advertisement
Add Comment
Please, Sign In to add comment