LivioBrunner

QuarrySender v.1.0

May 20th, 2015
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.24 KB | None | 0 0
  1. ---Init Constantes---
  2. modemSide = "back"
  3. ---------------------
  4.  
  5.  
  6. local modem = peripheral.wrap(modemSide)
  7. modem.open(1)
  8. local shutDown = false
  9. os.loadAPI("menu")
  10. function split(inputstr, sep)
  11.         if sep == nil then
  12.                 sep = "%s"
  13.         end
  14.         local t={} ; i=1
  15.         for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  16.                 t[i] = str
  17.                 i = i + 1
  18.         end
  19.         return t
  20. end
  21. function goForward()
  22.   modem.transmit(1,1,"forward")
  23. end
  24. function goBackward()
  25.   modem.transmit(1,1,"backward")
  26. end
  27. function goRight()
  28.   modem.transmit(1,1,"right")
  29. end
  30. function goLeft()
  31.   modem.transmit(1,1,"left")
  32. end
  33.  
  34. function shutDown()
  35.   shutDown = true
  36.   mon.Clear()
  37. end
  38.  
  39. function clear()
  40.   term.setCursorPos(1,1)
  41.   term.clear()
  42. end
  43.  
  44. cycle = function (parameters)
  45.   pout(parameters[2])
  46.   if parameters[0] == nil then
  47.    amount = 1
  48.   else
  49.    amount = tonumber(parameters[0])
  50.   end
  51.   if parameters[1] == nil then
  52.    cmd= "left"
  53.   else
  54.    cmd = parameters[1]
  55.   end
  56.   if parameters[2] == nil then
  57.    slp = 20
  58.   else
  59.    slp = tonumber(parameters[2])
  60.   end
  61.   for i=0, amount,1 do
  62.    modem.transmit(1,1,cmd)
  63.    os.sleep(slp)
  64.    pout("Cycle done:" .. i.. "/".. amount)
  65.   end
  66. end
  67. function wout(txt)
  68.   term.setTextColor(colors.green)
  69.   write(">".. txt)
  70.   term.setTextColor(colors.white)
  71. end
  72. function pout(txt)
  73.   term.setTextColor(colors.green)
  74.   print(">".. txt)
  75.   term.setTextColor(colors.white)
  76. end
  77. local commands = {}
  78. local commandsCounter = 0
  79. function addCommand(cmdtext, func)
  80.   commands[commandsCounter] = {commadtext = cmdtext, func = func}
  81.   commandsCounter = commandsCounter + 1
  82. end
  83.  
  84. function init()
  85.  addCommand("cycle", cycle)
  86.  addCommand("goLeft", goLeft)
  87.  addCommand("goRight", goRight)
  88.  addCommand("goForward", goForward)
  89.  addCommand("goBackward", goBackward)
  90.  while true do
  91.    wout("Command:")
  92.    command = read()
  93.    for i = 0,table.getn(commands),1 do
  94.      command = split(command, " ")
  95.      commandParameters = {}
  96.      if commands[i].commandtext == command[0] then
  97.          for i=2,table.getn(command), 1 do
  98.        commandParameters[i-2] = command[i]
  99.      end
  100.          commands[i].func(commandParameters)
  101.          break
  102.      end
  103.    end
  104.  end
  105. end
  106.  
  107. init()
Advertisement
Add Comment
Please, Sign In to add comment