I want to dynamize a display (for example color) based on two variables, how can I do that?

Q

I want to dynamize a display (for example color) based on two variables, how can I do that?

A

Nearly all default displays of atvise's library taking actions based on a single variable only. So any dynamization based on two or more variables needs to be programmed by yourself.

As a good starter we should first look what happens when a "Simple dynamic" on a simple box is used when "change color" action is selected.

Draw a box and use "Add Simple Dynamic" on it.

Under "Single Node" enter the source variable delivering the value that decides on the dynamization

Then choose "Color" as action, a "source value" with any fill color as shown.

You can now look to the source code using the script button that was created for this action.

 

Below find the resulting scripting code automatically created. It makes a data subscription to the selected variable and whenever the value is changed the functio(e) will be called:

 

webMI.data.subscribe("Server1/Device_1.Signal Group_1.Signal_1", function(e) {
var id = "id_0";
var value = e.value;
if (value == 0) webMI.gfx.setFill(id, "#ff2b8a");
});

If we now modify this source code by duplicating it manually you can get easily a dynamization depending on two differnet variables. In this case you have to work with global variables in order record values of the past from previous function calls.

 

var value_Signal_1;
var value_Signal_2;
 
webMI.data.subscribe("Server1/Device_1.Signal Group_1.Signal_1", function(e) {
var id = "id_0";
var value_Signal_1 = e.value;
 
if (value_Signal_1 == 0 && value_Signal_2 == 0) webMI.gfx.setFill(id, "#ff2b8a");
if (value_Signal_1 == 0 && value_Signal_2 == 1) webMI.gfx.setFill(id, "#002b8a");
if (value_Signal_1 == 1 && value_Signal_2 == 0) webMI.gfx.setFill(id, "#ff008a");
if (value_Signal_1 == 1 && value_Signal_2 == 1) webMI.gfx.setFill(id, "#333333");
 
});
 
webMI.data.subscribe("Server1/Device_1.Signal Group_1.Signal_2", function(e) {
var id = "id_0";
var value_Signal_2 = e.value;
 
if (value_Signal_1 == 0 && value_Signal_2 == 0) webMI.gfx.setFill(id, "#ff2b8a");
if (value_Signal_1 == 0 && value_Signal_2 == 1) webMI.gfx.setFill(id, "#002b8a");
if (value_Signal_1 == 1 && value_Signal_2 == 0) webMI.gfx.setFill(id, "#ff008a");
if (value_Signal_1 == 1 && value_Signal_2 == 1) webMI.gfx.setFill(id, "#333333");
 
});

Since atvise detects that the original source code has been modifed and is no standard dynamic any more it removes the possibility to click on the simple dynamics list.

 

 

 

Â