Posted 21 September 2012 - 07:34 AM
Hello!
So I created a program that simply makes a stair case. I really wanted to practice what I know of Lua, so that's what it is overly complex. It is version 1.0, so I know that it can be improved. For one it crashes when strings are inputed instead of numbers. But this is a known issue. :)/>/> Any ideas for other uses would be nice too. :D/>/>
So I created a program that simply makes a stair case. I really wanted to practice what I know of Lua, so that's what it is overly complex. It is version 1.0, so I know that it can be improved. For one it crashes when strings are inputed instead of numbers. But this is a known issue. :)/>/> Any ideas for other uses would be nice too. :D/>/>
local finished = false
local function stairPlaceUp()
turtle.up()
turtle.placeDown()
turtle.forward()
end
local function stairPlaceDown()
turtle.placeDown()
turtle.forward()
turtle.down()
end
local function refuel()
if turtle.getFuelLevel() < 1 then
for i = 1,16 do
turtle.select(i)
turtle.refuel()
end
turtle.select(1)
end
end
local function build()
for i = 1, height do
stairPlaceUp()
end
if width == 2 then
turtle.turnRight()
turtle.forward()
turtle.turnRight()
turtle.forward()
for i = 1, height do
stairPlaceDown()
end
else
turtle.turnRight()
turtle.turnRight()
for i = 1, height+1 do
turtle.forward()
turtle.down()
end
end
end
local function initialize()
w, h = term.getSize()
term.clear()
term.setCursorPos(1,1)
print("Stairs v1.0")
term.setCursorPos(w/2+1, 1)
print("by; soccerboy5411")
for i = 1, w-1 do
term.setCursorPos(i,2)
print("-")
end
term.setCursorPos(1,4)
end
function main()
initialize()
refuel()
local ques1 = true
local ques2 = true
while ques1 == true do
print("How high up? ")
height = tonumber(read())
--print(height)
if height < 1 or height == nil then
print("Please enter a positive number.")
else
ques1 = false
end
end
while ques2 == true do
print("Would you like it 1 or 2 blocks wide? ")
width = tonumber(read())
--print(width)
if width > 2 or width < 1 or width == nil then
print("Please pick 1 or 2 blocks wide.")
else
ques2 = false
end
end
build()
term.clear()
term.setCursorPos(1,1)
finished = true
end
while finished ~= true do
main()
end