Adding any character into the n1.connect() as parameter crashes studio. Note: nothing is running. Why is it doing that?
Here’s the code
local Node = {}
Node.new = function()
local self = {}
local adjacencies = {}
function self.connect(node, recurse : boolean)
if not table.find(adjacencies,node) then
table.insert(adjacencies, node)
if not recurse then
node.connect(self,true)
end
end
end
function self.disconnect(node, recurse : boolean)
local index = table.find(adjacencies, node)
if index then
table.remove(adjacencies,index)
if not recurse then
node.disconnect(self,true)
end
end
end
function self.getAdjacencies()
return adjacencies
end
return self
end
local n1 = Node.new()
local n2 = Node.new()
n1.connect()
I feel the same way. Please try it yourself, let me know if you get the same result (just put the code into a module, and then try to connect n1 to n2)
how you tried debugging? It’s seems that your function is recursive (means it calls it self) and it’s acting like a while loop, because you do first check if not node in the table then insert it, but the node argument is nil, so it never will be finded/inserted. Then you check if it’s not recursive then call function connect in the node, but you give no arguments to this function! Is it happends when you running this code without calling connect function?