Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function instructions()
- --here are the instructions for the program.
- print "please place 1 of the material you want the floor made from in slot 13"
- print "please place 1 of the item you want the walls made out of in slot 14"
- print "please place 1 of the item you want to make the roof our of in slot 15"
- print "please place fuel in slot 16"
- end
- -- investigate ways to shrink this code
- -- this is my function to compair the
- -- items in the first 12 slots of the turtle
- -- capable of compairing to any slot in the turtle
- -- need to make a check to make sure it
- -- is not compairing to itself.
- function comp(t)
- turtle.select(1)
- if turtle.compareTo(t) == true
- then s = 1
- return s
- else turtle.select(2)
- end
- if turtle.compareTo(t) == true
- then s = 2
- return s
- else turtle.select(3)
- end
- if turtle.compareTo(t) == true
- then s = 3
- return s
- else turtle.select(4)
- end
- if turtle.compareTo(t) == true
- then s = 4
- return s
- else turtle.select(5)
- end
- if turtle.compareTo(t) == true
- then s = 5
- return s
- else turtle.select(6)
- end
- if turtle.compareTo(t) == true
- then s = 6
- return s
- else turtle.select(7)
- end
- if turtle.compareTo(t) == true
- then s = 7
- return s
- else turtle.select(8)
- end
- if turtle.compareTo(t) == true
- then s = 8
- return s
- else turtle.select(9)
- end
- if turtle.compareTo(t) == true
- then s = 9
- return s
- else turtle.select(10)
- end
- if turtle.compareTo(t) == true
- then s = 10
- return s
- else turtle.select(11)
- end
- if turtle.compareTo(t) == true
- then s = 11
- return s
- else turtle.select(12)
- end
- if turtle.compareTo(t)
- then s = 12
- return s
- else print "no valid materials"
- end
- end
- --this function allows for the choosing
- -- of the dimensions of the building
- function getDim(x,y,z)
- print "please enter desired length:"
- l = io.read()
- print "please enter desired width:"
- w = io.read()
- print "please enter desired height:"
- h = io.read()
- print (l..w..h)
- return l, w, h
- end
- --floor building function
- function floor(x,t,c )
- t = 13
- comp(t,c)
- c = s
- for i = 1, x do
- turtle.digDown()
- turtle.placeDown()
- if turtle.getItemCount(c) == 0
- then comp(t,c)
- c = s
- end
- forward()
- end
- for i = 1, x do
- turtle.back()
- end
- turtle.turnRight()
- forward()
- turtle.turnLeft()
- fuel(c)
- end
- --wall building function
- function walls(x,y,t,c)
- t = 14
- comp(t,c)
- c = s
- turtle.placeDown()
- for k = 1 , x-1
- do forward()
- turtle.placeDown()
- if turtle.getItemCount(c) == 0
- then comp(t,c)
- c = s
- end
- fuel(c)
- end
- turtle.turnRight()
- forward()
- for i = 1 , y-2
- do if turtle.getItemCount(c) == 0
- then comp(t,c)
- c = s
- end
- turtle.placeDown()
- forward()
- end
- fuel(c)
- turtle.turnRight()
- end
- -- this is the function to make the roof
- function roof(x,y,t,c)
- t = 15
- comp(t,c)
- c = s
- turtle.forward()
- turtle.turnRight()
- turtle.forward()
- turtle.down()
- for i = 1 , x-2
- do for j = 1, y-2
- do if turtle.getItemCount(c) == 0
- then
- comp(t,c)
- c = s
- end
- turtle.placeDown()
- turtle.forward()
- end
- for k= 1, y-2
- do turtle.back()
- end
- turtle.turnLeft()
- forward()
- turtle.turnRight()
- end
- end
- -- refueling function
- function fuel(c)
- if turtle.getFuelLevel() <=500
- then turtle.select(16)
- turtle.refuel(2)
- print(turtle.getFuelLevel())
- turtle.select(c)
- end
- end
- -- functions included to reduce lines of code
- -- and to allow for a stuck check
- function forward()
- if turtle.forward() ~= true
- then turtle.dig() turtle.forward()
- end
- end
- function up()
- if turtle.up() ~= true
- then turtle.digup()
- turtle.up()
- fuel(c)
- else fuel(c)
- end
- end
- -- main program
- local x, y, z, t, c
- instructions()
- --sleep(7)
- getDim()
- x = l
- y = w
- z = h
- print (x..y..z)
- for j= 1, y do
- floor(x,t,c)
- end
- turtle.turnLeft()
- for j= 1, y do
- forward()
- end
- turtle.turnRight()
- up()
- for l= 1 , z
- do
- for m = 1 , 2
- do
- walls(x,y,t,c)
- end
- up()
- end
- roof(x,y,t,c)
- turtle.turnRight()
- for i = 1 , x
- forward()
- end
- turtle.turnRight()
- forward()
- turtle.turnLeft()
- for j = 1 . z
- do turtle.down
- end
Advertisement
Add Comment
Please, Sign In to add comment