Here's something I knocked up last night - seems to work
Code:
local Monitors = {}
function RegisterVariableWatch(varName, func) -- func should take two parameters varName, and varValue
Monitors[varName] = Monitors[varName] or {}
local temp = Monitors[varName]
temp[table.getn(temp)+1] = func
end
function OnVariableChange(varName, varValue)
local monList = Monitors[varName]
if monList then
for _, func in ipairs(monList) do
func(varName, varValue)
end
end
end
You just save this code as a .lua file in NRs \lua directory.
Obviously you need to delete or rename your OnVariableChange function or it will override this one. Here's an example from my CCF's lua file :-
Code:
function WatchFilter(varName, varValue)
NetRemote.ExecuteAction(-1, 0, 1, "LDJ.SELECTNAMEDFILTER("..varValue..")")
end
function OnCCFLoad()
RegisterVariableWatch('LDJ_Base_Filter_Type', WatchFilter)
end
Note that you can have more than one function monitoring the same variable. They will be called in the order that they are registered.
I think this looks cleaner than multiple conditions in the OnVariableChange function and might well be faster.
It wouldn't be hard to do something similar for OnPanelLoad