This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
EpicCenter's profile picture

Help With My Code

Started by EpicCenter, 23 September 2013 - 04:22 PM
EpicCenter #1
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.
Engineer #2
Posted 23 September 2013 - 06:26 PM
You forgot the parentheses on line 13. It should be turtle.dig()
EpicCenter #3
Posted 23 September 2013 - 07:08 PM
ty
EpicCenter #4
Posted 23 September 2013 - 07:15 PM
Apparently, there is the same error on line 30 somewhere.
campicus #5
Posted 23 September 2013 - 07:58 PM

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:

Spoiler

-- 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()
I have not tested this btw
EpicCenter #6
Posted 23 September 2013 - 07:58 PM
Fixed the most part of the errors, have one on line 53 now.
EpicCenter #7
Posted 23 September 2013 - 08:04 PM

distance = io.read() -- double "==" are only used when we are comparing a value, e.g., [if distance == 20 then]
distance = tonumber(distance)
Thank you for this.
EpicCenter #8
Posted 23 September 2013 - 08:29 PM

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:

Spoiler

-- 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()
I have not tested this btw
I now have an end of file error on line 52, Idk what that means.
EpicCenter #9
Posted 23 September 2013 - 08:31 PM

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:

Spoiler

-- 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()
I have not tested this btw
I now have an end of file error on line 52, Idk what that means.
nvm