I’m wondering if there’s an event that fires when you use table.insert because I want to know when an item is added to a table. Does anyone know if it exists?
Valkyrop
(JustAGuy)
May 29, 2022, 6:12am
#2
Maybe these could help -
Just create a function that you call instead of table.insert.
function addToInbox(message)
table.insert(inbox, message)
-- do extra stuff
end
If you’re into it, you could use a method on an Inbox class instead.
In general, for code clarity I would recommend avoiding relying on metatable methods like __newindex. It makes it so that you can’t trust what basic Lua operators like t[k] = v will do, it’s a power that must be used with great care.
Hello,
How would I use ChildAdded (or something of the sort) for tables? I’ve asked other people but they told me to use loops, which clogs and isn’t that good.
(Example of a loop that I DON’T want to use due to it being a loop, laggy, etc.)
local Table = {};
while wait() do
if #Table then
print(Table[#1] .." is a new value of our table.");
end;
end;
Is there a way to create a Table.ChildAdded and Table.ChildRemoved connection without using a loop?
It would need to respond to table.insert and table.remove. All implementations of this don’t directly respond to that.
I want to detect change in a table (like when something is added or changed)
supaTable = {
ToiletFlushed = false
Poop = {}
}
supaTable.ToiletFlushed = true
I don’t know how
If you do please let me know Thanks
You prob would need to use Metatables
2 Likes
Can I ask why you want to do this?
Presumably, you’re the one adding things to the table, so you already know when something new is added!
(There are legit reasons to want this, but it’s not necessarily the best solution)
1 Like
Yeah, I’ve changed my mind, I’ve moved the entire thing to right after table.insert.
1 Like