From f530d034adb79a256723878465214098301f167d Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 30 Apr 2012 15:00:40 +0200 Subject: [PATCH] added lib folder with some handy modules utils a library for some handy library functions now constains ask confirmation which takes a pre and post condition and asks you if you want to continue. Also a turtle module which allows you to test your code for syntax errors. --- lib/turtlePlaceholder | 18 ++++++++++++++++++ lib/utils | 17 +++++++++++++++++ makefloor | 36 +++++++++++++++++------------------- 3 files changed, 52 insertions(+), 19 deletions(-) create mode 100644 lib/turtlePlaceholder create mode 100644 lib/utils diff --git a/lib/turtlePlaceholder b/lib/turtlePlaceholder new file mode 100644 index 0000000..7f29663 --- /dev/null +++ b/lib/turtlePlaceholder @@ -0,0 +1,18 @@ +local function placeholder() return true end + +local turtle = {} + +turtle.up = placeholder +turtle.down = placeholder +turtle.digUp = placeholder +turtle.digDown = placeholder +turtle.dig = placeholder +turtle.forward = placeholder +turtle.turnLeft = placeholder +turtle.turnRight = placeholder +turtle.detect = placeholder +turtle.getItemCount = placeholder +turtle.placeDown = placeholder +turtle.select = placeholder + +return turtle diff --git a/lib/utils b/lib/utils new file mode 100644 index 0000000..67d0815 --- /dev/null +++ b/lib/utils @@ -0,0 +1,17 @@ +local function confirmExe(pre, post) + print("Pre:", pre) + print("Post:", post) + print("Do you want to continue Y/N [Y]: ") + local confirmation = io.stdin:read(1) + if (confirmation == 'n' or confirmation == 'N') then + print("Aborted") + return false + end + io.stdin:read("*a") -- clear stdin +end + +local utils = {} + +utils.confirmExecution = confirmExe + +return utils diff --git a/makefloor b/makefloor index 79c2c8c..634c251 100644 --- a/makefloor +++ b/makefloor @@ -1,21 +1,10 @@ local args = { ... } ---[[ -local function placeholder() return true end -local turtle = {} -turtle.up = placeholder -turtle.down = placeholder -turtle.digUp = placeholder -turtle.digDown = placeholder -turtle.dig = placeholder -turtle.forward = placeholder -turtle.turnLeft = placeholder -turtle.turnRight = placeholder -turtle.detect = placeholder -turtle.getItemCount = placeholder -turtle.placeDown = placeholder -turtle.select = placeholder -]] + +package.path = package.path .. ";" .. "lib/?" + +-- local turtle = require "turtlePlaceholder" +local utils = require "utils" local turnedLeft = nil if args[1] == "rightturn" or args[1] == "leftturn" then @@ -25,7 +14,12 @@ else return end -print(turnedLeft) +local pre = "A room with walls atleast 2 high and robot should start in a corner" +local post = "a room with a floor of $material" + +if not utils.confirmExecution(pre, post) then + return +end local curContainer = 1 turtle.select(curContainer) @@ -58,7 +52,6 @@ local function fillblock() couldTurn = checkIfNextTurn() end - turtle.up() if not selectMatStack() then return false end @@ -72,8 +65,13 @@ local function fillblock() else turtle.forward() end - turtle.down() return true end +while not detectDown() do + turtle.down() +end + +turtle.up() + while fillblock() do end