Help with adding a stop in script
I'm trying to make a random filter with 3d objects,
I made this script that makes the scenes change, but I still need to add for example after 3 seconds it stops rotating, and stop at one of the scenes.
Somebody could help me? Thanks!
// -----JS CODE-----
//@input float delay = 0.21 {"widget":"slider", "min":0.01, "max":1.0, "step":0.01}
//@input int trigger {"widget":"combobox", "values":[{"label":"Tap", "value":"0"}, {"label":"Mouth Open", "value":"1"}, {"label":"Raise Eyebrows", "value":"2"}, {"label":"Kiss", "value":"3"}]}
//@input SceneObject[] options
var stop = false
var hintsComponent = script.getSceneObject().createComponent("Component.HintsComponent");
var random, previousRandom = -1;
var running = false;
function initialize() {
if(script.options.length < 1) {
print("WARNING: No options were added.");
return;
}
var defined = true;
for(var i = 0; i < script.options.length; i++) {
if(script.options[i])
script.options[i].enabled = false;
else
defined = false;
}
if(script.options.length > 1)
running = true;
if(defined)
delayedEvent.reset(0);
else
print("ERROR: Some options are not defined.");
}
var delayedEvent = script.createEvent("DelayedCallbackEvent");
delayedEvent.bind(function(eventData) {
if(running) {
random = Math.floor(Math.random() * script.options.length);
while(random == previousRandom)
random = Math.floor(Math.random() * script.options.length);
if(previousRandom > -1)
script.options[previousRandom].enabled = false;
script.options[random].enabled = true;
previousRandom = random;
delayedEvent.reset(script.delay);
}
});
var event;
switch(script.trigger) {
case 0:
event = script.createEvent("TapEvent");
hintsComponent.showHint("lens_hint_tap", 4);
break;
case 1:
event = script.createEvent("MouthOpenedEvent");
event.faceIndex = 0;
hintsComponent.showHint("lens_hint_open_your_mouth", 4);
break;
case 2:
event = script.createEvent("BrowsRaisedEvent");
event.faceIndex = 0;
hintsComponent.showHint("lens_hint_raise_your_eyebrows", 4);
break;
case 3:
event = script.createEvent("KissStartedEvent");
event.faceIndex = 0;
hintsComponent.showHint("lens_hint_blow_a_kiss", 4);
break;
default:
print("ERROR: Something went wrong.")
}
event.bind(function (eventData) {
running = false;
});
initialize();
Hi Paula!
I think you're very close! You can use the same delayedCallbackEvent to set running = false as well. For example:
where the number inside reset is how long the delay you want to be in seconds.
Cheers!
Jonathan