Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
JavaScript: How to write to multiple outputs
#2
Hi,

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
}
Reply


Messages In This Thread
RE: JavaScript: How to write to multiple outputs - by iliaslamprou - 03-25-2023, 06:44 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)