Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Sequence = ""
- local i = 1
- local function resetTerm()
- term.clear()
- term.setCursorPos(1,1)
- end
- local function Split(inputstr,sep)
- if sep == nil then
- sep = "%s"
- end
- local t={}
- for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
- table.insert(t, str)
- end
- return t
- end
- resetTerm()
- local function CheckType(str) -- basic interpreter
- local funcStr = ""
- local f = Split(str)[1]
- local n = Split(str)[2]
- local g = Split(str)[3]
- local o = Split(str)[4]
- if f == "mf" or f == "f" then
- funcStr = "while turtle.detect() do turtle.dig() end turtle.forward()\n"
- elseif f == "mb" or f == "b" then
- funcStr = "turtle.back()"
- elseif f == "mu" or f == "u" then
- funcStr = "if turtle.detectUp() then turtle.digUp() end turtle.up()\n"
- elseif f == "md" or f == "d" then
- funcStr = "if turtle.detectDown() then turtle.digDown() end turtle.down()\n"
- end
- if f == "dig" or f == "ds" then
- funcStr = "turtle.dig()\n"
- elseif f == "digup" or f == "du" then
- funcStr = "turtle.digUp()\n"
- elseif f == "digdown" or f == "dd" then
- funcStr = "turtle.digDown()\n"
- end
- if f == "180" then
- funcStr = "turtle.turnRight() turtle.turnRight()\n"
- end
- if f == "l" or f == "left" then
- funcStr = "turtle.turnLeft()\n"
- elseif f == "r" or f == "right" then
- funcStr = "turtle.turnRight()\n"
- end
- if f == "select" or f == "s" then
- funcStr = "turtle.select("..n..")\n"
- end
- if f == "place" or f == "p" then
- funcStr = "turtle.place()\n"
- elseif f == "placeup" or f == "pu" then
- funcStr = "turtle.placeUp()\n"
- elseif f == "placedown" or f == "pd" then
- funcStr = "turtle.placeDown()\n"
- end
- if f == "loop" or f == "for" then
- funcStr = "for i = 1,"..n.." do\n"
- end
- if f == "end" or f == "endloop" or f == "endfor" then
- funcStr = "end\n"
- end
- if f == "refuel" then
- funcStr = "turtle.refuel()\n"
- end
- if f == "print" then
- funcStr = "print(" .. n .. ")"
- end
- if f == "break" then
- funcStr = "break\n"
- end
- if f == "if" then
- if n == "detect" then
- funcStr = "if turtle.detect() then\n"
- elseif n == "detectUp" then
- funcStr = "if turtle.detectUp() then\n"
- elseif n == "detectDown" then
- funcStr = "if turtle.detectDown() then\n"
- elseif n == "inspect" then
- local line = "has_block, data = turtle.inspect()\n"
- local ifline = "if data.name == " .. g .. " then\n"
- funcStr = line .. ifline
- elseif n == "inspectUp" then
- local line = "has_block, data = turtle.inspectUp()\n"
- local ifline = "if data.name == " .. g .. " then\n"
- funcStr = line .. ifline
- elseif n == "inspectDown" then
- local line = "has_block, data = turtle.inspectUp()\n"
- local ifline = "if data.name == " .. g .. " then\n"
- funcStr = line .. ifline
- end
- end
- return funcStr
- end
- while true do
- term.write("Instruction " .. i .. ": ")
- local r = read()
- if r == "go" then -- set off
- break
- elseif r == "restart" then
- Sequence = ""
- i = 1
- resetTerm()
- end
- local func = CheckType(r)
- if func then
- Sequence = Sequence .. func
- i = i + 1
- end
- end
- term.setCursorPos(1,1)
- term.clear()
- print("Running Sequence")
- local file = fs.open("smResult",'w')
- file.write(Sequence)
- file.close()
- loadstring(Sequence)()
Add Comment
Please, Sign In to add comment