|
| 16 Sep 2017 11:07 AM |
currentsession[player] = data local private = currentsession[player] setmetatable(currentsession[player], { __index = private; __newindex = function(self, it, value) --this won't fire rawset(private, it, value) print("hohohohoho") end }) currentsession[player] is another table that stores numbers
a different script is constantly changing those numbers
this snippit is inside of a module script
#code print("your mother") |
|
|
| Report Abuse |
|
|
kennydies
|
  |
| Joined: 15 Nov 2008 |
| Total Posts: 825 |
|
|
| 16 Sep 2017 11:09 AM |
Well are you ever setting the values of indices that are nil at first?
|
|
|
| Report Abuse |
|
|
|
| 16 Sep 2017 11:13 AM |
currentsession[player] = data
data is not nil, and none of the stuff inside it is either
#code print("your mother") |
|
|
| Report Abuse |
|
|
kennydies
|
  |
| Joined: 15 Nov 2008 |
| Total Posts: 825 |
|
|
| 16 Sep 2017 11:16 AM |
You said "currentsession[player] is another table that stores numbers a different script is constantly changing those numbers"
newindex won't be fired just by changing values.
|
|
|
| Report Abuse |
|
|
|
| 16 Sep 2017 05:22 PM |
--module example 1 (works)
local module = {}
local module_index = {["number"] = 5}
local meta = setmetatable(module, { __index = module_index; __newindex = function(this, it, val) rawset(module_index, it, val) print("timed") end; }) --module example 2 (wont work)
currentsession[player] = data local meta = setmetatable(private,{ __index = currentsession[player]; __newindex = function(self, it, value) rawset(self, it, value) print(currentsession[player][it]) end }) i mean it isnt much different, __index is the table with the content, and the table that's being given a metatable is empty, like example 1 only difference i see is that currentsession[player] is a table that has values AND tables inside of it
|
|
|
| Report Abuse |
|
|
| |
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 16 Sep 2017 05:58 PM |
Yes they are both different. As multiple people have already explained on your other thread, __newindex is only invoked if t[k] == nil. See that "rawset(self, it, value)" in the second one, yeah.
I highly suggest you stop using metatables because you virtually never need them on roblox. |
|
|
| Report Abuse |
|
|