Reputation: 17
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?
Upvotes: 0
Views: 1259
Reputation: 660
You need to use different mindset here:
const conditionedSignal = inputSignal.ge(10).ifThenElse(0, 1);
This is a scalarSignal class, not a JS Number!
Upvotes: 1
Reputation: 51
Spark AR Studio uses reactive programming, a declarative programming model that uses asynchronous data streams. This guide will cover the benefits and use of reactive programming within Spark AR Studio.
https://sparkar.facebook.com/ar-studio/learn/documentation/scripting/reactive/
Upvotes: 0
Reputation: 71
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);
Upvotes: 2