Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ######################################
- -- Exec Sign
- -- version 0.1
- -- http://hevohevo.hatenablog.com/
- -- Required: OpenPeripheral MOD
- -- Turtle basically goes forward.
- -- When he reaches an sign, run the program.
- -- Write functions to the sign
- -- Semicolon is important to order some functions.
- -- t = turtle
- -- ------------------
- -- | t.turnRight(); |
- -- | t.turnRight(); |
- -- | t.turnRight(); |
- -- | t.turnRight(); |
- -- ------------------
- -- |
- -- |
- -- |
- -- required OpenPeripheral MOD
- -- if not fs.exists ("openp/") then
- -- error("Required: OpenPeripheral MOD")
- -- end
- -- Config
- SIGN = "sign"
- function exec_sign()
- t=turtle
- local p = peripheral.wrap("front")
- if p then
- local text = p.getText()
- if string.find(text, "-->") then
- turtle.turnRight()
- elseif string.find(text, "<--") then
- turtle.turnLeft()
- else
- local func, err = loadstring(text)
- if not func then
- printError( err )
- return
- end
- setfenv(func, getfenv())
- local success, msg = pcall(func)
- if not success then
- printError( msg )
- end
- end
- else
- error("unrecognize sign.")
- end
- end
- function isType(type_name)
- return peripheral.getType("front")==type_name
- end
- while true do
- if turtle.detect() then
- if isType(SIGN) then
- print("detect a sign")
- exec_sign()
- else
- print("detect a block")
- end
- else
- turtle.forward()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement