STEAM GROUP
ComputerCraft MC_CC
STEAM GROUP
ComputerCraft MC_CC
0
IN-GAME
8
ONLINE
Founded
February 6, 2012
Russel Nov 10, 2012 @ 1:12pm
Code not working (Skipping to end of Function "Find")
Someone want to help me with this? its skipping to the end of the function whenever its called in the loop, i put print("It is calling the function") or something like that to see if it is, and it was, but it skips. The function was going to be used for turtle pathfinding, so i called it Find(xm,ym) Here is the code also i made some of the extra crap in the loop into comments to get them out of the way. Please help with this its extremely annoying...

function Find(xm,ym)
x=0
y=0
f=0
if xm>0 then
while not f==1 do
turtle.turnRight()
f=f+1
if f==4 then
f=0
else
print(f)
end
end
else if xm<0 then
while not f==3 do
turtle.turnRight()
f=f+1
if f==4 then
f=0
else
print(f)
end
end
end
while not x==xm do
if f==0 then
turtle.forward()
y=y+1
else if f==1 then
turtle.forward()
x=x+1
else if f==2 then
turtle.forward()
y=y-1
else if f==3 then
turtle.forward()
x=x-1
end
end
end
end
end
end
if ym>0 then
while not f==0 do
turtle.turnRight()
f=f+1
if f==4 then
f=0
else
print(f)
end
end
else if ym<0 then
while not f==3 do
turtle.turnRight()
f=f+1
if f==4 then
f=0
else
print(f)
end
end
end
while not y==ym do
if f==0 then
turtle.forward()
y=y+1
else if f==1 then
turtle.forward()
x=x+1
else if f==2 then
turtle.forward()
y=y-1
else if f==3 then
turtle.forward()
x=x-1
end
end
end
end
end
end
print("It is calling the function") --It skips to here whenever its called in the following loop
end

while true do
-- print(5>0)
Find(5,0) --All it does here is print("It is calling the function") :( dumbass computer
-- print("X is "..x..",Y is "..y..".")
-- print("Z is "..z..",F is "..f..".")
sleep(1)
end
Date Posted: Nov 10, 2012 @ 1:12pm
Posts: 0

More discussions