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:
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.