Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --{program="tPlatform",version="1.01",date="2013-11-09",basicFunc="1.10",basicFuncDate="2013-10-30",addFunc="0.00"",addFuncDate="n.a."}
- ---------------------------------------
- -- tPlatform by Kaikaku
- -- 2013-11-02, v1.00 initial
- -- 2013-11-09, v1.01 more compact
- ---------------------------------------
- -- basic functions: v1.10, 2013-10-30
- -- additional func: n.a.
- ---------------------------------------
- ---------------------------------------
- ---- PLANS AND IDEAS SO FAR -----------
- ---------------------------------------
- --done) build platforms dependant on
- -- user input
- -- 2) build walls
- -- 3) build roofs (i.e. diagonally)
- -- 4) execute multiple commands
- -- 5) maybe the final version could
- -- be used as API?
- -- 6) easy to use interface
- -- 7) use of a resupply chest
- -- 8) use of an enderchest
- -- 9) error handling
- -- 10) ...
- ---------------------------------------
- ---- ASSUMPTIONS/PRECONDITIONS --------
- ---------------------------------------
- -- Turtle movement:
- -- - building space must be empty
- ---------------------------------------
- ---- PARAMETERS -----------------------
- ---------------------------------------
- local cSleepTime=10
- ---------------------------------------
- ---- VARIABLES ------------------------
- ---------------------------------------
- local userX=3 userY=1
- local blnAskForParameters=true
- local blnDirectionX=true
- local currentSlot=1
- ---------------------------------------
- ---- tArgs ----------------------------
- ---------------------------------------
- local tArgs = {...}
- if #tArgs == 2 then -- no error check
- blnAskForParameters=false
- userX=tonumber(tArgs[1])
- userY=tonumber(tArgs[2])
- end
- ---------------------------------------
- -- basic functions for turtle control -
- ---------------------------------------
- local function mats()
- if turtle.getItemCount(currentSlot)==0 then
- currentSlot=currentSlot+1
- if currentSlot>16 then
- currentSlot=1
- print("Out of materials, please restock!")
- print(" Sleeping for "..cSleepTime.." sec ...")
- os.sleep(cSleepTime)
- end
- turtle.select(currentSlot)
- mats()
- end
- end
- local function gf() while not turtle.forward() do end end
- local function gb() while not turtle.back() do end end
- local function gu() while not turtle.up() do end end
- local function gd() while not turtle.down() do end end
- local function gl() while not turtle.turnLeft() do end end
- local function gr() while not turtle.turnRight() do end end
- local function df() turtle.dig() end
- local function du() turtle.digUp() end
- local function dd() turtle.digDown() end
- local function pf() mats() while not turtle.place() do end end
- local function pu() mats() while not turtle.placeUp() do end end
- local function pd() mats() while not turtle.placeDown() do end end
- local function sf() turtle.suck() end
- local function su() turtle.suckUp() end
- local function sd() turtle.suckDown() end
- local function Df() turtle.drop() end
- local function Du() turtle.dropUp() end
- local function Dd() turtle.dropDown() end
- local function ss(s) turtle.select(s) end
- local function waitKey(strText)
- local event, scancode
- write(strText)
- event, scancode = os.pullEvent("key")
- print()
- end
- ---------------------------------------
- -- additional functions ---------------
- ---------------------------------------
- function checkFuel() --checks if there is enough fuel and refuels when neded.
- if turtle.getFuelLevel()<10 then --if you are low on fuel
- print("refueling")
- turtle.select(14) --select the enderchest
- turtle.placeUp() --place the enderchest above you
- turtle.suckUp() --suck some fuel from the above enderchest into the current selected slot. (you cannot specify any amount or from which slot.)
- turtle.refuell(10) --refuel with one piece of fuel
- turtle.dropUp() --dump the rest of the fuel back in the enderchest. (can be left out of the code.)
- turtle.digUp() --digs up the enderchest above you and places it in your current selected iventory.
- else --if you are not low on fuel.
- --print("not low on fuel, carrying on with business. mining lasers n stuff.")
- end
- end
- -- n.a.
- ------------------------------------------------------------------------------
- -- main ----------------------------------------------------------------------
- ------------------------------------------------------------------------------
- -- step 0 usage hints
- term.clear() term.setCursorPos(1,1)
- print("+-------------------------------------+")
- print("| tPlatform, by Kaikaku |")
- print("+-------------------------------------+")
- print("| Put in building materials in any |")
- print("| slot(s) and press key. |")
- print("| Platform size: Enter x and y to |")
- print("| determine size. Either when asked |")
- print("| by program or with function call, |")
- print("| e.g., tPlatform 5 10 |")
- print("| If turtle runs out of materials it |")
- print("| waits until resupplied. |")
- print("+-------------------------------------+")
- -- step 1 get input
- if blnAskForParameters then
- waitKey("Put in materials + press key!")
- -- step 1.1 get x
- write("Enter depth x (default&min=3):")
- userX=read()
- if userX==nil or userX=="" then userX=3 end
- userX=tonumber(userX) -- no error check yet
- if userX<3 then userX=3 end
- -- step 1.2 get y
- write("Enter width y (default&min=1):")
- userY=read()
- if userY==nil or userY=="" then userY=3 end
- userY=tonumber(userY) -- no error check yet
- --if userY<2 then userY=2 end
- end
- userX=math.floor(userX)
- userY=math.floor(userY)
- -- step 2 check materials
- -- no check yet
- -- step 3 loopy loops ;)
- print("Let's build something nice:")
- -- step 3.1 go to start position
- -- & if odd number go back
- if userY%2==1 then
- -- odd number of rows
- for i=1,userX,1 do gf() end
- blnDirectionX=false
- else
- -- even number of rows
- gf() gf() gl() gl()
- blnDirectionX=true
- end
- -- step 3.2 build it
- for iY=1,userY,1 do
- for iX=1,userX-1 do
- if iX==1 then
- if iY~=1 then
- if blnDirectionX then
- gl()
- else
- gr()
- end
- end
- gb() pf()
- elseif iX==userX-1 then
- if iY~=userY then
- if blnDirectionX then
- -- right turn
- gr()
- else
- -- left turn
- gl()
- end
- end
- gb() pf()
- else -- in between start and end
- gb() pf()
- end
- end
- blnDirectionX=not blnDirectionX
- end
- -- go back within 1st row
- gr()
- for i=1,userY-1,1 do gb() pf() end
- gl() gb() pf()
- print("Done. Looks nice to me ;)")
- os.sleep(0.4)
- print("***************************************")
- print("* Check out YouTube for more videos *")
- print("* and turtle programs by Kaikaku :) *")
- print("***************************************")
Advertisement
Add Comment
Please, Sign In to add comment