Hello,
Is it possible to read the state of 1 or more virtual items in a UI Action script? When I use the ReadDirect function with an item it works but not with a virtual item.
Thanks.
Hello,
Is it possible to read the state of 1 or more virtual items in a UI Action script? When I use the ReadDirect function with an item it works but not with a virtual item.
Thanks.
Curzar08 ,
When targeting virtual items, you will need to add the prefix "virtual:" when specifying the item name. That being said, I'm not sure readDirect can handle virtual items. I just set up a test as shown below. The readValue function works correctly.
(function () {
var MODULE_NAME = "readDirect",
ENABLE_LOGGING = false,
RECORD_LOG = false,
logger = shmi.requires("visuals.tools.logging").createLogger(MODULE_NAME, ENABLE_LOGGING, RECORD_LOG),
fLog = logger.fLog,
log = logger.log,
module = shmi.pkg( MODULE_NAME );
/* private functions */
function readDirectCallback(err,response){
if(err){
console.log(err);
} else{
console.log(response);
}
}
/**
* Implements local-script run function.
*
* This function will be called each time a local-script will be enabled.
*
* @param {LocalScript} self instance reference of local-script control
*/
module.run = function (self) {
const im = shmi.requires("visuals.session.ItemManager"); //get reference to ItemManager instance
for (item in im.items){
console.log(`Item manager item: ${item}`);
}
testDirect = im.readDirect(["virtual:test"], readDirectCallback);
testRead = im.readValue("virtual:test");
console.log(`"Read value response: ${testRead}`);
/* called when this local-script is disabled */
self.onDisable = function () {
self.run = false; /* from original .onDisable function of LocalScript control */
};
};
// MODULE CODE - END
fLog("module loaded");
})();
Output: