Magic Link Tutorial throwing an error (SOLVED)

I am working in the tutorial in the “Mark Links” section and when I complete it and run I get an error when it checks if the block is in the blocklist.

I created a seperate project and downloaded the full code which compiles and runs without errors, and other than missing the code that comes later in the tutorial my code looks identical…

Here is the Error: (I added the print statements to check the function)
DEBUG:SCRIPT: function called
DEBUG:SCRIPT: preparing to check id
DEBUG:SCRIPT: hash: [/instance33]
DEBUG:SCRIPT: function called
DEBUG:SCRIPT: preparing to check id
ERROR:SCRIPT: main/board.script:102: attempt to index local ‘b’ (a userdata value)
stack traceback:
main/board.script:102: in function 'in_blocklist’
main/board.script:142: in function <main/board.script:110>

here is the code:

--
--does the block exist in the list of blocks?
--
local function in_blocklist(blocks, block)
print("function called")
	for i, b in pairs(blocks) do
	print("preparing to check id")
		if b.id == block then
		print(b.id)
			return true
		end
	end
	return false
end

And here is the blocklist code:

local function build_blocklist(self)
	self.blocks = {}
	for x, l in pairs(self.board) do
		for y, b in pairs(self.board[x]) do
			table.insert(self.blocks, {id = b.id, color = b.color, x = b.x, y=b.y})
		end
	end
end

They do look functionally the same.

Post your whole script here, rename to .lua and you can upload (admin, maybe add .script and .gui_script to upload list?)

board.lua (4.5 KB)

Line 131

table.insert(self.chain, self.board[x][y].id)

should be

table.insert(self.chain, self.board[x][y])

2 Likes

Added extensions .script and .gui_script too.

1 Like