Advertisement
IMarvinTPA

Triggered Transposer

Oct 20th, 2014
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.76 KB | None | 0 0
  1. --pastebin get zMtrhwZT startup
  2. --pastebin get zMtrhwZT redtransposer
  3.  
  4. --shell.run("redtransposer r f b")
  5. --shell.run("redtransposer r t b")
  6. --shell.run("redtransposer r t rf")
  7.  
  8. local tArgs = { ... }
  9. local sTrigger, sInput, sOutput, nDelay = tArgs[1], tArgs[2], tArgs[3], tArgs[4]
  10. local nSlots = tArgs[5]
  11. local filename = shell.getRunningProgram()
  12.  
  13. if not trans then
  14.     os.loadAPI("trans")
  15.     if not trans then
  16.         shell.run("pastebin get 68xNzDAV trans")
  17.         os.loadAPI("trans")
  18.         if not trans then
  19.             error("Unable to load 'trans' API")
  20.         end
  21.     end
  22. end
  23.  
  24. sTrigger = trans.fixSide(sTrigger)
  25. sInput = trans.fixSide(sInput)
  26. sOutput = trans.fixSide(sOutput)
  27.  
  28. if sTrigger == nil or sInput == nil or sOutput == nil then
  29.     print( "Usage: " .. filename .. " <signal side> <input side> <output side> [Delay Time]" )
  30.     print( "Side values are Top, Bottom, Front, and None" )
  31.     print( "The turtle will pull from the input side and push into the output side." )
  32.     print( "None can be specified if the turtle is expected to deal with items moving on their own." )
  33.     print( "Slots: Maximum number of stacks to pull at one time.")
  34.     return
  35. end
  36.  
  37. if nDelay ~= nil then
  38.     nDelay = tonumber(nDelay)
  39. end
  40.  
  41. if nDelay == nil then
  42.     nDelay = 0.5
  43. end
  44.  
  45. if nSlots ~= nil then
  46.     nSlots = tonumber(nSlots)
  47. end
  48.  
  49. if nSlots == nil then
  50.     nSlots = 15
  51. end
  52.  
  53. if nSlots < 1 or nSlots > 16 then
  54.     nSlots = 15
  55. end
  56.  
  57. print( "Transposing from " .. trans.displaySide(sInput) .. " to " .. trans.displaySide(sOutput) .. " with a delay of " .. nDelay .. " seconds and loading up to " .. nSlots .. " slots while signal from " .. trans.displaySide(sTrigger) .. "." )
  58.  
  59.  
  60. while true do
  61.     if trans.readSide(sTrigger) then
  62.         trans.load(sInput, 1, nSlots)
  63.         trans.unload(sOutput, "n")
  64.     end
  65.     sleep(nDelay)
  66. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement