Posted 23 September 2013 - 06:22 PM
I have some variables in this code and it says that in line 14, there is an equals sign expected. Here is the code for download. Here's something else, I want to have the whole thing debugged.
distance = io.read() -- double "==" are only used when we are comparing a value, e.g., [if distance == 20 then]
distance = tonumber(distance)
-- Branch Mining Script
-- Variables
local distance = nil
-- Functions
-- Digging Functions
function digFwd()
repeat
turtle.dig()
sleep(0.4)
until turtle.forward() --Your turtle wouldn't have moved forward before
end
function digUp()
repeat
sleep(0.4)
until not turtle.digUp() --this just makes your code a bit neater
end
-- Input Function
function input()
print("How many meters is this mine going to go?")
distance = io.read()
distance = tonumber(distance)
end
-- Input Phase
term.clear()
term.setCursorPos(1,1)
print("This is a branch mining program.")
print("--------------------------------")
input() --you forgot parentheses here
-- Digging the mine
turtle.dig()
turtle.forward()
distance = distance - 1 --only need the one "=" here
repeat
digUp()
digFwd()
distance = distance - 1 --again only need one "="
until distance == 0 --here we have two "="s because we are comparing two values
turtle.digUp()
Thank you for this.distance = io.read() -- double "==" are only used when we are comparing a value, e.g., [if distance == 20 then] distance = tonumber(distance)
I now have an end of file error on line 52, Idk what that means.distance = io.read() -- double "==" are only used when we are comparing a value, e.g., [if distance == 20 then] distance = tonumber(distance)
EDIT: In continuing reading:
You are using 'while' loops in a weird way. A while loops is used to loop code but you are not wanting anything looped. Take a look at your code rewritten:I have not tested this btwSpoiler
-- Branch Mining Script -- Variables local distance = nil -- Functions -- Digging Functions function digFwd() repeat turtle.dig() sleep(0.4) until turtle.forward() --Your turtle wouldn't have moved forward before end function digUp() repeat sleep(0.4) until not turtle.digUp() --this just makes your code a bit neater end -- Input Function function input() print("How many meters is this mine going to go?") distance = io.read() distance = tonumber(distance) end -- Input Phase term.clear() term.setCursorPos(1,1) print("This is a branch mining program.") print("--------------------------------") input() --you forgot parentheses here -- Digging the mine turtle.dig() turtle.forward() distance = distance - 1 --only need the one "=" here repeat digUp() digFwd() distance = distance - 1 --again only need one "=" until distance == 0 --here we have two "="s because we are comparing two values turtle.digUp()
nvmI now have an end of file error on line 52, Idk what that means.distance = io.read() -- double "==" are only used when we are comparing a value, e.g., [if distance == 20 then] distance = tonumber(distance)
EDIT: In continuing reading:
You are using 'while' loops in a weird way. A while loops is used to loop code but you are not wanting anything looped. Take a look at your code rewritten:I have not tested this btwSpoiler
-- Branch Mining Script -- Variables local distance = nil -- Functions -- Digging Functions function digFwd() repeat turtle.dig() sleep(0.4) until turtle.forward() --Your turtle wouldn't have moved forward before end function digUp() repeat sleep(0.4) until not turtle.digUp() --this just makes your code a bit neater end -- Input Function function input() print("How many meters is this mine going to go?") distance = io.read() distance = tonumber(distance) end -- Input Phase term.clear() term.setCursorPos(1,1) print("This is a branch mining program.") print("--------------------------------") input() --you forgot parentheses here -- Digging the mine turtle.dig() turtle.forward() distance = distance - 1 --only need the one "=" here repeat digUp() digFwd() distance = distance - 1 --again only need one "=" until distance == 0 --here we have two "="s because we are comparing two values turtle.digUp()