I don't understand why if-else construction doesn't work.
const Diagnostics = require('Diagnostics');
const Reactive = require('Reactive');
var num = 5;
var firstCondition= false;
var secondCondition = false;
function func(){
firstCondition = Reactive.ge(num, 10);
secondCondition = Reactive.lt(num, 10);
if(firstCondition){ //false
num = 0;
} else if(secondCondition){ //true
num = 1;
}
}
func();
Diagnostics.watch("num - ", num);
Diagnostics.watch("firstCondition ", firstCondition);
Diagnostics.watch("secondCondition ", secondCondition);
num shows 0:( What am I doing wrong? Is it specific of reactive programming?
There are two issues in your example:
if (firstCondition.pinLastValue())
to get the value of the boolean signal.secondly, I guess your function is not updated, you need something like this:
const Time = require('Time'); const interval = Time.setInterval(func(), 500);