Sysvar Hook Example
You can use the left-click context menu to enable autoupdate, to see the hooks in action.
Documentation
The Sysvar function supports a hook as a parameter to alter the value at runtime.
So the values 0/1 can be translated to ON/OFF or some image-tags with an image representing the state.
But if you want to add color on minimum and maximum, you can simply use "sysvar("uln[0]", MIN(200), MAX(250))".
Example
/*
* This hook transforms ranges to text.
* < 200 V => "Voltage to low."
* > 230 V => "Voltage to high."
* else => "Voltage ok."
*
*/
function hook_uln(sysvarobj){
var volt = parseInt(sysvarobj.value); // e.g. "230.33 V" to 320.33 integer
if (volt < 200) // Under 200 V?
sysvarobj.value = "Voltage to low.";
else {
if (volt > 250) // Over 200V
sysvarobj.value = "Voltage to high.";
else // between 200-250V
sysvarobj.value = "Voltage ok.";
}
return true;// Yes use the modification
}
...
myTable.AddCell(sysvar("_ULN[0]", HOOK(hook_uln) ));
...
For more examples, see the source code of this document.
function callback(sysvarobj)
This is the prototype for a callback function, which is passed to the sysvar function by ...,HOOK(callback),....
The first parameter "sysvarobj" has the following members variables:
- varnameThe Sysvar name as uppercase, eg. "_ULN[0]"
- value The value, eg. "230,52 V".
The new value should be stored in "sysvarobj.value".
If the callback function returns true, the callee will use the content of "sysvarobj.value" since it is passed by reference.
If otherwise the function returns false, changes will be ignored.
One callback function can be used by serveral sysvar functions (see hook_box in this site source). You can use varname to determine which sysvar called.