Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
-- TODO -- actor (rednet) -- blueprints -- relative coords/facing -- return home -- waypoints -- Done -- history -- save -- infinite loop -- decimals for sleep command -- join plans for between loop iterations -- -- mini language for making scripts smaller -- and doing ad-hoc commands faster -- -- look down in the handlers for all the commands -- you can put a number afterwards to repeat a single command -- you can put parenthesis around a list and a number after that to repeat several commands -- detect and compare will break out of parethesis -- -- examples: -- Chop down tree to a max height of 48 -- -- Dff(?uDuu)48d48 -- -- Here is how the commands are interpreted -- -- Df - turtle.dig() -- f - turtle.forward() -- ( - for i = 1, 48 do -- ?u - if not turtle.detectUp() then break end -- Du - turtle.digUp() -- u - turtle.up() -- ) 48 - end -- d 48 - for i = 1, 48 do turtle.down() end -- -- You can use the language in other scripts like so -- -- os.loadAPI("act") -- act.act("f5rrf5ll") -- act internal functions local forward = 0 local up = 1 local down = 2 local tMove = {[forward] = turtle.forward, [up] = turtle.up, [down] = turtle.down} local tDetect = {[forward] = turtle.detect, [up] = turtle.detectUp, [down] = turtle.detectDown} local tAttack = {[forward] = turtle.attack, [up] = turtle.attackUp, [down] = turtle.attackDown} local tDig = {[forward] = turtle.dig, [up] = turtle.digUp, [down] = turtle.digDown} local tPlace = {[forward] = turtle.place, [up] = turtle.placeUp, [down] = turtle.placeDown} local function tryDir(dir) while not tMove[dir]() do if tDetect[dir]() then tDig[dir]() else tAttack[dir]() end end return true end -- act turtle functions function try() return tryDir(forward) end function tryUp() return tryDir(up) end function tryDown() return tryDir(down) end local currentSlot = 1 function select(slot) currentSlot = slot turtle.select(slot) return true end local function findSimilar() for s = 1, 16 do if s ~= currentSlot then turtle.select(s) if turtle.compareTo(currentSlot) then turtle.select(currentSlot) return s end end end turtle.select(currentSlot) return nil end local function buildDir(dir) if turtle.getItemCount(currentSlot) == 1 then local resupplySlot = findSimilar() if resupplySlot then if tPlace[dir]() then turtle.select(resupplySlot) turtle.transferTo(currentSlot, turtle.getItemCount(resupplySlot)) turtle.select(currentSlot) return true else return false end else return tPlace[dir]() end else return tPlace[dir]() end end function build() return placeDir(forward) end function buildUp() return placeDir(up) end function buildDown() return placeDir(down) end function zzz(n) sleep(n) return true end -- command handlers local tHandlers = { -- move ["f"] = turtle.forward, ["b"] = turtle.back, ["u"] = turtle.up, ["d"] = turtle.down, ["l"] = turtle.turnLeft, ["r"] = turtle.turnRight, -- others ["s"] = select, ["t"] = turtle.transferTo, ["R"] = turtle.refuel, -- dig ["Df"] = turtle.dig, ["Du"] = turtle.digUp, ["Dd"] = turtle.digDown, -- attach ["Af"] = turtle.attack, ["Au"] = turtle.attackUp, ["Ad"] = turtle.attackDown, -- place ["Pf"] = turtle.place, ["Pu"] = turtle.placeUp, ["Pd"] = turtle.placeDown, -- build ["Bf"] = build, ["Bu"] = buildUp, ["Bd"] = buildDown, -- suck ["Sf"] = turtle.suck, ["Su"] = turtle.suckUp, ["Sd"] = turtle.suckDown, -- drop (E for eject) ["Ef"] = turtle.drop, ["Eu"] = turtle.dropUp, ["Ed"] = turtle.dropDown, -- try, dig routine with anti-gravel/sand and anti-mob logic ["Tf"] = try, ["Tu"] = tryUp, ["Td"] = tryDown, -- detect ["?f"] = turtle.detect, ["?u"] = turtle.detectUp, ["?d"] = turtle.detectDown, -- compare ["=f"] = turtle.compare, ["=u"] = turtle.compareUp, ["=d"] = turtle.compareDown, ["=="] = turtle.compareTo, ["z"] = zzz --sleepddo } function getNumber(s, pos, max, default) if s:sub(pos + 1, pos + 1) == "*" then pos = pos + 1 return math.huge, pos elseif tonumber(s:sub(pos + 1, pos + 1)) == nil then return default, pos else local n = "" local decimal = false while pos <= max and (tonumber(s:sub(pos + 1, pos + 1)) ~= nil or (not decimal and s:sub(pos + 1, pos + 1) == ".")) do if s:sub(pos + 1, pos + 1) == "." then decimal = true end pos = pos + 1 n = n .. s:sub(pos, pos) end return tonumber(n), pos end end function parsePlan(actions, worker) if not worker then worker = "" end actions = actions:gsub("[ \t\n]", "") local plan = {} plan["plan"] = {} plan["worker"] = "" plan["join"] = {} plan["count"] = 1 -- get worker local pos = actions:find(":") if pos then local pos2 = actions:find("(", 1, true) if pos2 == nil or pos2 > pos then plan["worker"] = actions:sub(1, pos - 1) actions = actions:sub(pos + 1) end else plan["worker"] = worker end plan["plan"], plan["join"], workers, found_action = parseActions(actions, plan["worker"]) if join_workers then for k, v in pairs(join_workers) do workers[k] = v end end if found_action or join_found_action then workers[plan["worker"]] = true end local worker_count = 0 local last_worker = nil for k, v in pairs(workers) do worker_count = worker_count + 1 last_worker = k end plan["atomic"] = worker_count <= 1 if worker_count == 1 then plan["worker"] = last_worker end return plan, workers end function parseActions(actions, worker) local plan = {} local join_plan = nil local cur_plan = plan local workers = {} local found_action = false local pos = 1 local max = actions:len() while pos <= max do local c = actions:sub(pos, pos) if c == "(" then -- read until matching ) local p = 1 local sub_actions = "" while p > 0 and pos <= max do pos = pos + 1 c = actions:sub(pos, pos) if c == ")" then p = p - 1 if p < 0 then error("unmatched ')'") end elseif c == "(" then p = p + 1 end if p > 0 then sub_actions = sub_actions .. c end end if p > 0 then error("unmatched '('") end -- get optional count local n = nil n, pos = getNumber(actions, pos, max, 1) -- call recursively local sub_plan, sub_workers = parsePlan(sub_actions, worker) sub_plan["count"] = n table.insert(cur_plan, sub_plan) for k, v in pairs(sub_workers) do workers[k] = true end elseif c == "/" then if cur_plan == join_plan then error("mulitple '/' found") else join_plan = {} cur_plan = join_plan end else -- 2 character commands if c == "D" or c == "A" or c == "P" or c == "S" or c == "E" or c == "T" or c == "?" or c == "=" then pos = pos + 1 c = c .. actions:sub(pos, pos) end n, pos = getNumber(actions, pos, max, 1) if tHandlers[c] then table.insert(cur_plan, { action=c, count=n }) found_action = true else error("Unknown action '"..c.."'") end end pos = pos + 1 end return plan, join_plan, workers, found_action end function compilePlan(plan) --print("===============") --print(type(plan)) --tprint(plan) if not plan["plan"] then error("can't compile plan") end if plan["atomic"] then local actions = "" for i, item in ipairs(plan["plan"]) do if item["action"] then actions = actions .. item["action"] if item["count"] > 1 then actions = actions .. item["count"] end elseif item["plan"] then actions = actions .. compilePlan(item)["compiled"] else error("can't compile unknown plan item") end end if plan["join"] then actions = actions .. "/" .. compilePlan(plan["join"])["compiled"] end if plan["count"] > 1 then actions = "(" .. actions .. ")" .. plan["count"] end return {worker=plan["worker"], compiled=actions} else local plans = {} local actions = {} for i, item in ipairs(plan["plan"]) do if item["plan"] then if #actions > 0 then table.insert(plans, compilePlan({ plan=actions, atomic=true, count=1, worker=plan["worker"] })) actions = {} end table.insert(plans, compilePlan(item)) elseif item["action"] then table.insert(actions, item) end end if #actions > 0 then table.insert(plans, compilePlan({ plan=actions, atomic=true, count=1, worker=plan["worker"] })) actions = {} end return {plan=plans, count=plan["count"]} end end function act(plan) local found_sub = false local pos = 1 local max = plan:len() while pos <= max do local c = plan:sub(pos, pos) if c == " " or c == "\t" or c == "\n" then -- ignore whitespace elseif c == "(" then found_sub = true -- read until matching ) local p = 1 local sub_plan = "" local main_plan = "" local join_plan = "" while p > 0 do pos = pos + 1 c = plan:sub(pos, pos) if c == ")" then p = p - 1 elseif c == "(" then p = p + 1 end if c == "/" and p == 1 then -- split plan main_plan = sub_plan sub_plan = "" elseif p > 0 then sub_plan = sub_plan .. c end end if main_plan ~= "" then join_plan = sub_plan else main_plan = sub_plan end -- get optional count local n = nil n, pos = getNumber(plan, pos, max, 1) -- call recursively for i = 1, n, 1 do if act(main_plan, n) then if join_plan ~= "" and i ~= n then if not act(join_plan) then print("sub plan (join) failure") end end else print("sub plan (main) failure") return false end end elseif c == ":" then if found_sub then print("worker must be at beginning of sub_plan") end else if c == "D" or c == "A" or c == "P" or c == "S" or c == "E" or c == "T" or c == "?" or c == "=" then pos = pos + 1 c = c .. plan:sub(pos, pos) end -- call handler local fn = tHandlers[c] if fn then if c == "f" or c == "b" or c == "u" or c == "d" or c == "l" or c == "r" or c == "Tf" or c == "Td" or c == "Tu" then -- move handlers, number defines iterations -- get optional count local n = nil n, pos = getNumber(plan, pos, max, 1) for i = 1, n, 1 do if not fn() then if turtle.getFuelLevel() == 0 then print("Out of fuel") return false -- stop entire plan else print("Blocked: " .. plan:sub(1, pos) .. " / " .. plan:sub(pos + 1)) return false -- stop entire plan end end end elseif c:sub(1,1) == "?" or c:sub(1,1) == "=" then -- detect and compare, failure will only skip out of the current block local result = nil if c == "==" then local n = nil n, pos = getNumber(plan, pos, max, 1) result = fn(n) else result = fn() end if not result then return true -- stop current plan end else -- all other handlers, number gets passed to function if c == "t" then -- look for 2 numbers local n1 = nil local n2 = nil n1, pos = getNumber(plan, pos, max) pos = pos + 1 if pos <= max then local c2 = plan:sub(pos, pos) if c2 == "," then if pos <= max then n2, pos = getNumber(plan, pos, max) if not fn(n1, n2) then print("Can't perform action: "..c) end else print("expecting second number") end else print("expecting comma") end else print("expecting second number") end else local n = nil n, pos = getNumber(plan, pos, max) if n == nil then if not fn() then print("Can't perform action: " .. c) end else if not fn(n) then print("Can't perform action: " .. c) -- return false end end end end else print("Unknown command: " .. c) return false end end pos = pos + 1 end return true end function tprint (tbl, indent) if not indent then indent = 0 end for k, v in pairs(tbl) do formatting = string.rep(" ", indent) .. k .. ": " if type(v) == "table" then print(formatting) tprint(v, indent+1) elseif type(v) == "boolean" then print(formatting .. tostring(v)) else print(formatting .. v) end end end
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
I made $15,000 in 2 days
CSS | 12 min ago | 0.21 KB
✅ API Glitch (Docs Leak)
CSS | 13 min ago | 0.21 KB
This summer smells like money
CSS | 13 min ago | 0.21 KB
Untitled
mIRC | 3 hours ago | 0.57 KB
ifm isu iolink [WIP]
Python | 4 hours ago | 1.18 KB
HELLO PROGRAMMER
18 hours ago | 0.03 KB
Untitled
23 hours ago | 2.26 KB
FB2600 User Handbook v0.91
1 day ago | 6.06 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!