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

[help] goto function not working [help]

Started by chriskopp7, 18 May 2013 - 07:26 AM
chriskopp7 #1
Posted 18 May 2013 - 09:26 AM
i can not seem to get the goto function to work, i did not want to use the gps api for this program. i do have miscperphals so i have the compass module and a teleported in front of the turtle.
pastebin; http://pastebin.com/LMxbrasS and if you are lazy


m = peripheral.wrap("front")
c = peripheral.wrap("right")
facing = c.getFacing()
x = 0
y = 0
canMove = false
function canMove()
	if turtle.detect() then
		return false
	else
		return true
	end
end
function move()
	if canMove() then
		turtle.forward()
		if facing == 0 then
			y = y -1
		end
		if facing == 1 then
			x = x +1
		end
		if facing == 2 then
			y = y +1
		end
		if facing == 3 then
			x = x -1
		end
	end
	print("x = "..x.." y = "..y.."")
end
--the turning fuction
function face(f)
	facing = c.getFacing()
	while facing ~= f do
		turtle.turnLeft()
		facing = c.getFacing()
	end
end
-- move to function	
function goto(goX,goY)
--turn at portal
	if x ==0 and y == 0 and facing~= 2 then
		face(2)
	end
	--get out of middle
	function leaveMiddle()
		if goY ~= y or goX ~= x then
			if x ~=0 or x ~= 6 and y ~= 15 then
				if goX == 6 then
					face(3)
				else
					face(1)
				end
			end
			while x ~= goX do
				move()
			end
		end
	end
	-- goto right side
	if goY ~= y or goX ~= x then
		if goX == 6 and x ~= 6 then
			if y ~= 3 or y ~= 15 then
				if  y > 9 then
					face(2)
					while y ~= 15 do
						move()
					end
				end
				if y < 9 and y > 3 then
					face(0)
					while y ~= 3 do
						move()
					end
				end
				if y < 3 then
					face(3)
					while y < 3 do
						move()
					end
				end
			end
		end
	end
	if goY > y and goY ~= y then
		face(2)
	else
	if goY < y and goY ~= y then
		face(0)
	end
	while y ~= goY do
		move()
	end
end
function getBookOne()
	goto(1,1)
end
getBookOne()
H4X0RZ #2
Posted 18 May 2013 - 09:28 AM
I think you mean the goto frm batch, and this isn't available in lua :)/>
chriskopp7 #3
Posted 18 May 2013 - 09:30 AM
I think you mean the goto frm batch, and this isn't available in lua :)/>
No i do not mean goto from batch. Did you even look at the code?
chriskopp7 #4
Posted 18 May 2013 - 10:18 AM
fixed the code just have some issue with little things.