I have a script for a Spark AR Instagram Filter. I want it to be an which... are you filter. My Problem is, that i can't start the filter by tapping on the screen. I think it only starts going through th main loop, but I have no Idea on why it stops. Am I using old APIs or Functions?
Here is my code:
// Spark AR APIs
const Time = require('Time');
const Patches = require('Patches');
const Instruction = require('Instruction');
const Materials = require('Materials');
const Textures = require('Textures')
// Objects
const display0 = Materials.getAll('display');
const pics = ['pic1', 'pic2', 'pic3'];
// Variables
let randInterval = null;
let status = 'ready';
// Setting Initial Instruction
Instruction.bind(true, 'tap_to_start');
// Main loop
Patches.outputs.getPulse('tap').then(value => value.subscribe(() => {
Instruction.bind(false, 'tap_to_start')
if (status === 'ready') {
start();
}
else if (status === 'running'){
return;
}
else if (status === 'finished'){
reset();
}
}));
// Functions
function start(){
status = 'running';
randInterval = Time.setInterval(function (){
randomImage();
}, 100);
beginCountDown();
};
function beginCountDown(){
Time.setTimeout(function(){
stop();
}, 3000);
};
function stop(){
Time.clearInterval(randInterval);
Instruction.bind(true, 'tap_to_reply')
status = "finished";
};
function reset(){
Instruction.bind(false, 'tap_to_reply')
Instruction.bind(true, 'tap_to_start')
display0.diffuse = Textures.get('SPARKLE');
status = 'ready';
};
// Logic Functions
function randomImage(){
let randomNumber = randomlyChoose(0, pics.length);
let pickedImage = pics[randomNumber]
display0.diffuse = Textures.get(pickedImage);
};
function randomlyChoose(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min)
};