Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --BuildWall by KapitanWalnut
- --Version 0.1.0 3/7/2014
- --Will build a wall of specific size
- -- Config
- version = "0.1.0"
- topY = 10
- botY =0
- leftSide = 0
- rightSide = 10
- placedValue = 0
- minedValue = 0
- heightQuestion = true
- widthQuestion = true
- stacksQuestion = true
- -- Functions
- function getVersion() --returns version number
- return version
- end
- function regWrite(string, columnVar, rowVar) --write a string to specified coords
- term.setCursorPos(columnVar, rowVar)
- write(string)
- end
- function arcWrite(number, columnVar, rowVar) --writes a number to specified coords, takes digits into account
- digits = math.ceil(math.log10(number))
- if 10^digits == number then
- digits = digits + 1
- end
- term.setCursorPos(columnVar, rowVar)
- while digits > 1 do
- digits = digits - 1
- columnVar = columnVar - 1
- term.setCursorPos(columnVar, rowVar)
- end
- write(number)
- end
- function clearScreen() --clears screen and prints version, author
- term.clear()
- regWrite("BuildWall", 12, 1)
- regWrite(getVersion(), 2, 12)
- regWrite("by KapitanWalnut", 17, 12)
- term.setCursorPos(1, 3)
- end
- function drawTable() --prints a table on screen display infor during run time
- clearScreen()
- print([[
- +--------------------------------+
- |Blocks Placed: 0 |
- |Blocks Mined: 0 |
- +--------------------------------+
- | Status |
- |[ ]|
- | 0% |
- +--------------------------------+
- ]] )
- placedValue = 0
- minedValue = 0
- end
- function updateTable() --updates table during runtime
- --Update Blocks
- arcWrite(placedValue, 33, 4)
- arcWrite(minedValue, 33, 5)
- --Update Percentage
- if height > 0 then
- area = (height * width)
- else
- area = placedValue
- end
- percentage = math.ceil((placedValue / area) * 100)
- arcWrite(percentage, 19, 9)
- --Update Percentage Bar
- percentageBar = math.floor(percentage * 0.3)
- columnVar = 4
- while percentageBar > 0 do
- regWrite("=", columnVar, 8)
- percentageBar = percentageBar - 1
- columnVar = columnVar + 1
- end
- end
- --Digging Functions
- function digDown() --Dig Down and update table
- if turtle.detectDown() then
- turtle.digDown()
- minedValue = minedValue + 1
- end
- updateTable()
- end
- function digUp() -- Dig up and update table
- while turtle.detectUp() do
- turtle.digUp()
- sleep(0.4)
- minedValue = minedValue + 1
- end
- updateTable()
- end
- function digForward() --Dig Forward and update table
- while turtle.detect() do
- turtle.dig()
- sleep(0.4)
- minedValue = minedValue + 1
- end
- updateTable()
- end
- --Movement Functions
- function moveForward()--Move forward no digging
- moved = false
- repeat
- if turtle.forward() then
- moved = true
- else
- moved = false
- end
- until moved == true
- end
- function moveDown()--Move down no digging
- moved = false
- repeat
- if turtle.down() then
- moved = true
- else
- moved = false
- end
- until moved == true
- end
- function moveUp()--Move forward no digging
- moved = false
- repeat
- if turtle.up() then
- moved = true
- else
- moved = false
- end
- until moved == true
- end
- --Questions
- function askQuestions() --asks Questions
- --Get Height
- clearScreen()
- while heightQuestion == true do
- print("Height of wall?")
- height = tonumber(read())
- clearScreen()
- if height == nil then
- print("Must be a number.")
- elseif height >= 2 then
- heightQuestion = false
- else
- print("Wall must be taller then one.")
- end
- end
- --Get Width
- clearScreen()
- while widthQuestion == true do
- print("Width of Wall?")
- width = tonumber(read())
- clearScreen()
- if width == nil then
- print("Must be a number.")
- elseif width > 0 then
- widthQuestion = false
- else
- print("Width must be greater then 0")
- end
- end
- --make sure enough blocks are in inv
- clearScreen()
- while stacksQuestion == true do
- area = width * height
- stackNum = math.ceil(area/64)
- if stackNum > 16 then --too big, reask questions
- print("Area is too big!")
- print("Requires ", stackNum, " stacks!")
- print("Can only hold 16 stacks!")
- print("")
- print("Press Enter to reinput size...")
- dummy = read()
- heightQuestion = true
- widthQuestion = true
- stacksQuestion = true
- askQuestions()
- else
- print("Do I have ", stackNum, " stacks?")
- answer = string.lower(read())
- clearScreen()
- if answer == ('yes') then
- stacksQuestion = false
- elseif answer == ('no') then
- print("Add them!")
- else
- print("Answer yes or no.")
- end
- end
- end
- end
- --main function
- function main()
- askQuestions()
- drawTable()
- end
- --run main function
- main()
Advertisement
Add Comment
Please, Sign In to add comment