As title states, I had it working a second ago but all of a sudden it’s just stopped working so I can imagine it’s something small, not too sure though, any help appreciated.
Since payloadInfo.currentPosition isn’t nil, it doesn’t invoke the __newindex method, so either:
A. Just run the newindex function whenever you change the property manually.
B. Create a “fake table” that gets indexed to make __newindex works.
I believe there was a module that did this, but here’s an example.
local fakeTable = {}
local realTable = {
gaming = true
}
setmetatable(fakeTable, {
__newindex = function(table, index, value)
realTable[index] = value
-- Do what you need to do when current position changes --
end,
__index = function(table, index)
return realTable[index]
end
})
fakeTable.currentPosition = 5
When you assign a value to an absent index in a table and if the table has a metamethod attached to it, then the interpreter looks for a __newindex metamethod: If there is one, the interpreter calls it instead of making the assignment
This is where you can get the full info:. https://www.lua.org/pil/13.4.2.html