-
Notifications
You must be signed in to change notification settings - Fork 11
addChangeHandler
Dawi edited this page Jan 24, 2014
·
1 revision
Description
This function will be performed when a value in a table changes.
Syntax
addChangeHandler(table,"value",function)
Example
function broadcastScore(self, newvalue)
outputChatBox("The Score is now "..tostring(newvalue))
end
local tab = {}
addChangeHandler(tab, "score", broadcastScore)
tab.score = 12 -- "The Score is now 12"
But you can use it to set a value as read only too.
function readOnlyScore(self, newvalue)
-- The old value will be returned so the newvalue will be ignored
return self.score
end
local tab = {}
tab.score = 12
addChangeHandler(tab, "score", readOnlyScore)
tab.score = 15
print(tab.score) -- 12