of     1   

cjcool12345
#63562428Tuesday, February 28, 2012 2:38 AM GMT

I am making a new flag system. Inside it is a table that I will be used to store connections. After a while, I wont need the connections. I am hoping that there is a way to remove the connections with the lua garbage collector. So, is there any metamethod that I can attach to the table that will be attached to a function that will disconnect the connection, then remove it (instead of just remove it normaly)?
AbstractAlex
#63563847Tuesday, February 28, 2012 3:01 AM GMT

When you do not need the connection, just disconnect it function variable:disconnect() I don't know why you'd do it any other way.
epicfail22
#63563968Tuesday, February 28, 2012 3:03 AM GMT

connection = Part.Touched:connect(function() print('blah') end) connection:disconnect()
cjcool12345
#63564043Tuesday, February 28, 2012 3:04 AM GMT

But I will be having multiple connections, it would be easier for me to keep track of them in a table.
epicfail22
#63564165Tuesday, February 28, 2012 3:06 AM GMT

ConnectionTable = {} connection = Part.Touched:connect(function() print('touched') end) ConnectionTable[1]=connection function Disconnect() for k, v in pairs(ConnectionTable) do v:disconnect() end end
cjcool12345
#63564951Tuesday, February 28, 2012 3:21 AM GMT

Well, I was hoping for a method that would use the garbage collector for collecting other parts at the same time. But this method does work, and I can refine it to work in a script in a more customised way (though not like I would of though of). Thanks
JulienDethurens
#63565053Tuesday, February 28, 2012 3:23 AM GMT

Just put them all in a table and make that table a weak table. And disconnect them when you don't need them anymore. Here's an example: local connections = setmetatable({}, {__mode = 'kv'}) Just put the connections in the connections table and disconnect them when you don't need them. The garbage collector will pick them up, because the connections table is a weak table.
cjcool12345
#63565173Tuesday, February 28, 2012 3:25 AM GMT

But will that method disconnect the event at the same time, or just stop reference to them?
cjcool12345
#63567706Tuesday, February 28, 2012 4:22 AM GMT

would it work to get the gc metamethod to take in each connection as a value then get that function to manualy disconnect it?
AbstractAlex
#63582191Tuesday, February 28, 2012 8:36 PM GMT

We have answered your question. What you're trying to do makes no sense to us. It sounds to me like you do not know much about RBX.Lua. If you want a connection to disconnect after a certain amount of time, just disconnect it when you want it disconnected.
cjcool12345
#63588897Tuesday, February 28, 2012 10:47 PM GMT

Sounds like you don't understand the Lua Garbage Collector (can't blame you, its not fully working in Roblox and not often used). I will still be looking into the garbage collector method, but you are 1/4 (according to last post) percent right (do not just assume please; I do understand the RBX.Lua Object Oriented Programming). Go ahead, call this question answered, but I will continue to look around for the answer. Question Closed

    of     1