03-25-2023, 06:44 PM
Hi,
You have to include the messages for each ouput tag inside an array like the example below:
the better way is to create a json message for each tag first and store them to variables like the example below
//... code
result1 = '{"tag":"outputTag1", "value":'+ value1+ '};
//..code
result2 = '{"tag":"outputTag2", "value":'+ value2+ '};
//..code
result3 = '{"tag":"outputTag3", "value":'+ value3+ '};
result = [result1, result2, result2]
This is a completed example.
Create three tags:
inputTag - V0 (Script runner tag)
outputTag1 -V1
outputTag2 - V2
You have to include the messages for each ouput tag inside an array like the example below:
[{"tag":"outputTag1","value":'+ value1+'},{"tag":"outputTag2","value":'+ value2+'}]
the better way is to create a json message for each tag first and store them to variables like the example below
//... code
result1 = '{"tag":"outputTag1", "value":'+ value1+ '};
//..code
result2 = '{"tag":"outputTag2", "value":'+ value2+ '};
//..code
result3 = '{"tag":"outputTag3", "value":'+ value3+ '};
result = [result1, result2, result2]
This is a completed example.
Create three tags:
inputTag - V0 (Script runner tag)
outputTag1 -V1
outputTag2 - V2
Code:
//--- Copy values from Virtuino Variables to JavaScript variables
var inputValue = Virtuino.readValue("inputTag"); //Read inputTag value as String.
//--- enter the JavaScript code like the example below
if ((inputValue!=null) & (!isNaN(inputValue))) {
const x=100;
var newValue1 = x * inputValue;
//create the json for outputTag1
result1 = '{"tag":"outputTag1", "value":'+ newValue1+ '}';
const y=1000;
var newValue2 = y * inputValue;
//create the json for outputTag2
result2 = '{"tag":"outputTag2", "value":'+ newValue2+ '}';
//create the final array
result= [result1,result2];
}
else { // no input value available yet
result = null; // return null if you don't want to send a value to output variable
}