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

Error ambiguous syntax (function call x new statment)

Started by Computer--Xeon, 20 August 2014 - 04:24 AM
Computer--Xeon #1
Posted 20 August 2014 - 06:24 AM
I need help with my code I keep getting the error, ambiguous syntax, for line 106. My program is made for a turtle to map out a maze and store it as a table. The error is when I try to add onto d (direction map as 1 forward, 2 right, 3 back, and 4 right).
Here's my code:

print("Mapper 2D V1.0.0")
Map = {}
i = 1
n = 1
dir = 1
function save(table,name)
local file = fs.open(name,"w")
file.write(textutils.serialize(table))
file.close()
end
function load(name)
local file = fs.open(name,"r")
local data = file.readAll()
file.close()
return textutils.unserialize(data)
end
function search(dir)
	if dir == 1 then
	if turtle.detect() then
		Map[i] = 1
	end
	if turtle.detectLeft() then
		Map[i+1] = 1
	end
	if turtle.detectRight() then
		Map[i-1] = 1
	end
		if not turtle.detect() then
		Map[i] = 0
	end
	if not turtle.detectLeft() then
		Map[i+1] = 0
	end
	if not turtle.detectRight() then
		Map[i-1] = 0
	end
	save(Map,Map(n))
end
if dir == 2 then
	if turtle.detect() then
		Map[i+1] = 1
	end
	if turtle.detectLeft() then
		Map[i+10] = 1
	end
	if turtle.detectRight() then
		Map[i-10] = 1
	end
		if not turtle.detect() then
		Map[i+1] = 0
	end
	if not turtle.detectLeft() then
		Map[i+10] = 0
	end
	if not turtle.detectRight() then
		Map[i-10] = 0
	end
	save(Map,Map(n))
end
if dir == 3 then
	if turtle.detect() then
		Map[i-10] = 1
	end
	if turtle.detectLeft() then
		Map[i+1] = 1
	end
	if turtle.detectRight() then
		Map[i-1] = 1
	end
		if not turtle.detect() then
		Map[i-10] = 0
	end
	if not turtle.detectLeft() then
		Map[i+1] = 0
	end
	if not turtle.detectRight() then
		Map[i-1] = 0
	end
	save(Map,Map(n))
end
if dir == 4 then
	if turtle.detect() then
		Map[i-1] = 1
	end
	if turtle.detectLeft() then
		Map[i-10] = 1
	end
	if turtle.detectRight() then
		Map[i+10] = 1
	end
		if not turtle.detect() then
		Map[i-1] = 0
	end
	if not turtle.detectLeft() then
		Map[i-10] = 0
	end
	if not turtle.detectRight() then
		Map[i+10] = 0
	end
	save(Map,Map(n))
end
end

function turnlefts()
	search
	(dir + 1)
	turtle.turnLeft()
	search
end
function turnrights()
	search
	(dir - 1)
	turtle.turnRight()
	search
end
function intersection()
   if turtle.detect() then
	turnLeft()
	   if turtle.detect() then
		turnLeft()
		turnLeft()
		   if turtle.detect() then
			turnRight()
  end
  end
  end
end
function forwards()
	search
	turtle.forward()
	itersection()
	search  
end
turtle.select(1)
while turtle.compareDown() do
forwards()
end
Tell me whats wrong.
Dog #2
Posted 20 August 2014 - 08:20 AM
One thing that stands out to me is how you are referencing your search function. Currently you are attempting to call the variable pointing to the function…

search

you are missing the brackets/parentheses after the name

search()

However, your search function expects a variable as well (dir) so you should include the expected numeric value - for example…

search(1)

Also, in your function forwards() you misspelled intersection (you spelled it as itersection)

Hope that helps :)/>
Edited on 20 August 2014 - 06:25 AM
Dragon53535 #3
Posted 20 August 2014 - 08:36 AM
One thing that stands out to me is how you are referencing your search function. Currently you are attempting to call the variable pointing to the function…

search

you are missing the brackets/parentheses after the name

search()

However, your search function expects a variable as well (dir) so you should include the expected numeric value - for example…

search(1)

Hope that helps :)/>
He's actually already done so, however he moved it onto the next line as

search
(dir + 1)
You shouldn't get an error if you just move that next to search
HOWEVER, the second search in that function has the problem you stated.
Edited on 20 August 2014 - 06:36 AM
Computer--Xeon #4
Posted 20 August 2014 - 10:32 PM
Thanks for the help. That fix the problem. :lol:/>