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

[Error] attempt to index ? (a function value)

Started by Chub1337, 02 March 2012 - 05:27 PM
Chub1337 #1
Posted 02 March 2012 - 06:27 PM
So I've been writing this program now for a few hours already, it's called Trémauxbot (Trémaux as in the trémaux algorithm for solving mazes).

And I've stumbled upon this error message:

tremauxbot : 621 : attempt to index ? (a function value)

At line 621 is the following:

   dir1 = move[x][y+1]

dir1 is assigned as a local variable at the top of my program (local dir1 = 0)
and move[x][y+1] are assigned at the top aswell using:


--Table
write("Width of the maze in blocks?[x-coords] > ")
width = tonumber(read())
write("Height of the maze in blocks?[y-coords]  > ")
height = tonumber(read())
maze = {}
for x=1,width,1 do
maze[x] = {}
end
for x=1,width,1 do
for y=1,height,1 do
  maze[x][y] = 0
end
end

What could be the cause of this error, I've been staring at it for ages but still don't know what's wrong..

-Chub1337

P.S. The code around line 621 is:

Spoiler

  elseif dir == 3 then
   dir1 = move[x][y+1]
   if forward == true then
    dir2 = move[x][y-1]
    if right == true then
	 dir3 = move[x-1][y]
    else
	 dir3 = move[x+1][y]
    end
   else
    dir2 = move[x-1][y]
    dir3 = move[x+1][y]
   end
Casper7526 #2
Posted 02 March 2012 - 06:36 PM
I see you assigning maze, but using move
Chub1337 #3
Posted 03 March 2012 - 07:42 AM
I see you assigning maze, but using move

Oh.. My.. How could I miss that!?
I probably called it move because it is in the function move(), but damn that I didn't notice that..

Thanks Casper7526, it doesn't give the error now anymore :unsure:/>/> (though it neither works that well either, but that must be a because of somewhere else in the code…)

-Chub1337