97 posts
Posted 05 February 2014 - 12:08 PM
For some odd reason I keep getting an attemp to call boolien on line 73 and I can't figure out why it's happening. The print stuff is temporary and for getting bugs out of my code.
Http//:
www.pastebin.com/Yy1zc3kc
Edited on 05 February 2014 - 11:11 AM
91 posts
Posted 05 February 2014 - 12:18 PM
On line 66 you overwrite you function with false.
Edited on 05 February 2014 - 11:19 AM
97 posts
Posted 05 February 2014 - 01:52 PM
Thanks. It works now but it seems no matter where I put x = false to reset it I get that error. Even at the bottom in the while loop line.
Is there a way I can reset it back to false?
286 posts
Location
United States
Posted 05 February 2014 - 02:35 PM
Here is your code which I posted for others to review. I could not spot the problem.
x = false
function border()
print("checking")
turtle.select(16)
if turtle.compare() == true then
turtle.turnLeft()
if turtle.forward() == false then
turtle.back()
turtle.turnLeft()
end
end
end
function glow()
print("glow")
turtle.select(15)
if turtle.compare() == true then
glow = true
else
glow = false
end
end
function dump()
turtle.select(14)
turtle.placeDown()
s = 1
for i=1,13 do
turtle.select(s)
turtle.dropDown(64)
s = s + 1
sleep(0.2)
end
turtle.select(14)
turtle.digDown()
end
function forward()
print("forward")
while not turtle.forward() do
border()
turtle.select(1)
turtle.dig()
turtle.attack()
sleep(0.5)
end
end
function turn()
if x == false then
turtle.turnLeft()
forward()
turtle.turnLeft()
x = true
else
turtle.turnRight()
forward()
turtle.turnRight()
x = false
end
end
function dig()
if glow == true then
turn = false
print("digging")
forward()
for i = 1,3 do
forward()
forward()
print(x)
turn()
end
forward()
dump()
else
sleep(120)
end
end
while true do
border()
glow()
dig()
end
You could declare x as a local x at the beginning.
Edited on 05 February 2014 - 01:36 PM
91 posts
Posted 05 February 2014 - 02:36 PM
Post your new code. I don't see anything wrong in the old code if you only changed that one thing.
Also, I just noticed in one of your loops you use this
s = 1
for i=1,13 do
turtle.select(s)
turtle.dropDown(64)
s = s + 1
sleep(0.2)
end
You can just use i from the for loop:
for i=1,13 do
turtle.select(i)
turtle.dropDown(64)
sleep(0.2)
end
7083 posts
Location
Tasmania (AU)
Posted 05 February 2014 - 06:30 PM
When you do this:
function someVar()
print("This is a function")
end
… you're defining a function, which is assigned to the "someVar" variable. "someVar()" calls the function in "someVar".
Say you later do this:
someVar = true
Now "someVar" no longer leads to a function, but instead has a boolean (true/false) value stored against it. "someVar()" would attempt to call a function in "someVar", but since it now contains a boolean instead, you can guess what error comes up.
This means that eg calling your "glow" function results in it replacing
itself with a boolean, and calling your "dig" function may result in your "turn" function being affected the same way.
195 posts
Location
Cambridgeshire, England
Posted 06 February 2014 - 07:54 AM
Heres a major problem:
function glow()
print("glow")
turtle.select(15)
if turtle.compare() == true then
glow = true
else
glow = false
end
end
You create a function glow(). Then you overwrite glow() with true or false so instead of glow being a function it is a boolean. There is your issue.
Swap glow = true for return true.
I think you need to look at the lua API documentation on how functions work.