ByDefault
|
  |
| Joined: 25 Jul 2014 |
| Total Posts: 3197 |
|
|
| 25 Mar 2015 03:03 PM |
| I was just wondering if there is any way to fire a function when a table is changed (a value is added or removed). |
|
|
| Report Abuse |
|
|
|
| 25 Mar 2015 03:04 PM |
| I don't think so... It wouldn't be usefull anyway since you can only use tables in one script... |
|
|
| Report Abuse |
|
|
LucasLua
|
  |
| Joined: 18 Jun 2008 |
| Total Posts: 7386 |
|
|
| 25 Mar 2015 03:06 PM |
| This can be accomplished using metamethods and possibly a wrapper for your table. |
|
|
| Report Abuse |
|
|
Bebee2
|
  |
| Joined: 17 May 2009 |
| Total Posts: 3985 |
|
|
| 25 Mar 2015 03:11 PM |
-- Example
function createObj(tab) tab = tab and tab or true and {} tab.Changed = LoadLibrary'RbxUtility'.CreateSignal() local userdata = newproxy(true) local metatab = getmetatable(userdata)
metatab.__index = function(s, i) return tab[i] end
metatab.__newindex = function(s, i, v) if i ~= 'Changed' and tab[i] ~= v then tab.Changed:fire(i, v) return tab[i] end end
return userdata end
local tab = createObj() tab.Changed:connect(function(i,v) print(i, v) end) tab.lol = 3 |
|
|
| Report Abuse |
|
|
| |
|
|
| 25 Mar 2015 04:00 PM |
"tab = tab and tab or true and {}" Please do not do that.
tab = tab or {} |
|
|
| Report Abuse |
|
|