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

Functions not working

Started by mokera101, 14 June 2014 - 06:00 PM
mokera101 #1
Posted 14 June 2014 - 08:00 PM
Hello all. I'm new to programming and would like to gain a little bit of insight on something I've been working on, a program kind of like excavate but that uses an enderchest and mines 3 layers at a time. I know for the most part the code functions well at least from the area of the clearTheLevel() function I haven't tested toTheTop() yet or the primary if and while statement at the bottom.

What I'm running into is every time I try to add functions to the code like it is now I get an "= expected" at whatever line the first function is at and I haven't been able to find any articles online that address this issue and the code will work without adding the functions. So I know the simple answer is take the functions out but I don't want to do that.

The goal of the program is pretty simple a quick and and dirty way to mine without having to have a power system set up that a quarry would need. Plus eventually in a separate program add the ability to move 2 chunkloaders around; unless anyone knows an easier way to make turtles chunk load in either the monster or direworf20 1.6.4 packs.



code
x = 1
z = 1
turnCount = 1
slot = 2
depth = 0
whileDepth = 0

Function clearInventory() – places an enderchest and clears the turtles inventory
turtle.digUp()
turtle.select(1)
turtle.placeUp()
slot = 2
for slot = 2,16 do
turtle.select(slot)
turtle.dropUp()
end
turtle.select(1)
turtle.digUp()
end

function toTheTop() – takes the turtle back to the starting point
while depth > 0 do
turtle.up()
depth = depth - 1
end
if turnCount = 1 then
turtle.turnLeft()
turtle.turnLeft()
else
turtle.turnRight
for x = 1,32 do
turtle.forward()
end
turtle.turnLeft()
end
end

function isThereGravel() – checks to make sure nothing is blocking the turtle from moving forward
if turtle.forward() == false then
while turtle.forward() == false do
turtle.dig()
turtle.attack()
end
end
end

function clearTheLevel() – clears a 32x32 area that is 3 deep
for z = 1,32 do
for x = 1,32 do
turtle.getItemCount(15)
if turtle.getItemCount(15) > 0 then
clearInventory()
end

turtle.digUp()
turtle.digDown()
if x < 32 then
turtle.dig()
isThereGravel()
else
if z < 32 then
if turnCount == 1 then
turtle.turnRight()
turtle.dig()
isThereGravel()
turtle.turnRight()
turnCount = 2
else
turtle.turnLeft()
turtle.dig()
isThereGravel()
turtle.turnLeft()
turnCount = 1
end
else
turtle.turnLeft()
turtle.turnLeft()
if turtle.down() == true then
depth = depth + 1
end
end
end
end
end
end

– starts the program and runs until bedrock

if turtle.getItemCount(1) == 1 then
clearTheLevel()
while turtle.down() == true do
turtle.digDown()
whileDepth = whileDepth + 1
if whileDepth == 2 then
clearTheLevel()
whileDepth = 0
end
end
toTheTop()
else
print "I need my chest!!!"
end
/code
Lyqyd #2
Posted 14 June 2014 - 08:24 PM
Lua is case sensitive, so "Function" and "function" are two different things. The lower-case version is correct.