Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---Init Constantes---
- modemSide = "back"
- ---------------------
- local modem = peripheral.wrap(modemSide)
- modem.open(1)
- local shutDown = false
- os.loadAPI("menu")
- function split(inputstr, sep)
- if sep == nil then
- sep = "%s"
- end
- local t={} ; i=1
- for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
- t[i] = str
- i = i + 1
- end
- return t
- end
- function goForward()
- modem.transmit(1,1,"forward")
- end
- function goBackward()
- modem.transmit(1,1,"backward")
- end
- function goRight()
- modem.transmit(1,1,"right")
- end
- function goLeft()
- modem.transmit(1,1,"left")
- end
- function shutDown()
- shutDown = true
- mon.Clear()
- end
- function clear()
- term.setCursorPos(1,1)
- term.clear()
- end
- cycle = function (parameters)
- pout(parameters[2])
- if parameters[0] == nil then
- amount = 1
- else
- amount = tonumber(parameters[0])
- end
- if parameters[1] == nil then
- cmd= "left"
- else
- cmd = parameters[1]
- end
- if parameters[2] == nil then
- slp = 20
- else
- slp = tonumber(parameters[2])
- end
- for i=0, amount,1 do
- modem.transmit(1,1,cmd)
- os.sleep(slp)
- pout("Cycle done:" .. i.. "/".. amount)
- end
- end
- function wout(txt)
- term.setTextColor(colors.green)
- write(">".. txt)
- term.setTextColor(colors.white)
- end
- function pout(txt)
- term.setTextColor(colors.green)
- print(">".. txt)
- term.setTextColor(colors.white)
- end
- local commands = {}
- local commandsCounter = 0
- function addCommand(cmdtext, func)
- commands[commandsCounter] = {commadtext = cmdtext, func = func}
- commandsCounter = commandsCounter + 1
- end
- function init()
- addCommand("cycle", cycle)
- addCommand("goLeft", goLeft)
- addCommand("goRight", goRight)
- addCommand("goForward", goForward)
- addCommand("goBackward", goBackward)
- while true do
- wout("Command:")
- command = read()
- for i = 0,table.getn(commands),1 do
- command = split(command, " ")
- commandParameters = {}
- if commands[i].commandtext == command[0] then
- for i=2,table.getn(command), 1 do
- commandParameters[i-2] = command[i]
- end
- commands[i].func(commandParameters)
- break
- end
- end
- end
- end
- init()
Advertisement
Add Comment
Please, Sign In to add comment