Posted 10 September 2012 - 11:40 PM
Hello!
This is my first "real" program, and by real I mean not completely useless.
I'm not sure if this has been done before, probably has though, but whatever. Practice makes perfect.
This program will tell you how many blocks you need to build a house by using a slightly modified Surface Area equation. So let's say that you put this
Length:4
Width:6
Heighth:10(Doesn't include floor)
Then it would calculate exactly how many blocks(Including Roof and Floor) you need to build a house with these dimensions.
Im still working on the builder for it, find it a little complicated, but I'm confident.
For now, ignore what it says about building, and just type "no" if it prompts to ask you if you want to build.
Here's the code!
Please tell me if the code is actually giving the right amount of blocks plz!
This is my first "real" program, and by real I mean not completely useless.
I'm not sure if this has been done before, probably has though, but whatever. Practice makes perfect.
This program will tell you how many blocks you need to build a house by using a slightly modified Surface Area equation. So let's say that you put this
Length:4
Width:6
Heighth:10(Doesn't include floor)
Then it would calculate exactly how many blocks(Including Roof and Floor) you need to build a house with these dimensions.
Im still working on the builder for it, find it a little complicated, but I'm confident.
For now, ignore what it says about building, and just type "no" if it prompts to ask you if you want to build.
Here's the code!
function iGotEnough()
if response=="yes" then
print("Initiating building stage")
Build()
end
if response=="no" then
print("OK, stopping program")
end
end
function Total()
l=length-1
w=width-1
h=heighth-1
base1=2*(w*h)
base2=2*(l*h)
roofAndFloor=2*(length*width)
total=base1+base2+roofAndFloor
print("I need "..total.." blocks to make a house with these dimensions")
end
function getTotalItemCount()
local a="I currently have "
local b=" blocks"
ItemAmount=0
for f=1,16 do
ItemAmount=ItemAmount+turtle.getItemCount(f)
end
print()
print(a..ItemAmount.. :D/>/>
end
function RequiredAmount()
if ItemAmount >= total then
write("I have enought blocks to build, proceed?:")
response=read()
iGotEnough()
end
if ItemAmount < total then
print("I don't have enough blocks, please insert the correct amount of blocks and run this program again.")
end
end
function ReadyUp()
print("All sides must exceed 2")
write("Enter Length:")
length=read()
write("Enter Width:")
width=read()
write("Enter Heighth:")
heighth=read()
end
function FloorAndRoof()
turtle.forward()
turtle.forward()
for m=1,width do
turtle.turnRight()
turtle.forward()
turtle.turnRight()
for n=1,length do
turtle.digDown()
turtle.placeDown()
turtle.forward()
end
end
end
function Build()
FloorAndRoof()
end
ReadyUp()
Total()
getTotalItemCount()
RequiredAmount()
Please tell me if the code is actually giving the right amount of blocks plz!