JavaScript trigger if
-
Hello,
is it possible to work with triggers in the js actor?
Eg. output trigger by if statement or funktion triggered by input.
Best
Dill -
Could you tell us a bit more?
You can use a Trigger by using a mutated output (attach something with a Trigger to the output of the JavaScript actor)
Simply sending a 1 would fire the trigger.
-
javascript actor will accept triggers but it only sees them as a boolean, so you to wrap everything in an if statement so that it only runs that code when it's true.
this is especially important if you have multiple inputs (your trigger, and another value that changes more often), as the javascript actor will run every time it receives inputs.
likewise for trigger outputs - you can output to a trigger, but if you have one constantly changing argument the trigger will be firing constantly also - but this can be solved by running it through a value changed actor and using the trigger output of that
There is probably a much more elegant solution (someone please hop in if so!), but this is what I've found to work well.
Tim
-
@juriaan oooh interesting - in which case this may be a bug?
See how trigger here is continually firing - while the trigger going through value changed (which is behaving correctly in this instance) is not?
-
Thank you, this works for the input.
But an output allways triggers if any of the inputs are changed, despite any code there is. Even without any code at all. I guess this is the same issue there is, with the Global values actors?
These trigger outputs even when activating a scene or user actor without any intended rule to do so.
Therefore the only solution is, to go with integer 0/1 and a comparator connected.
I remember a forum discussion and an explanation by Mark about this, but can´t remember the exact reason for it. -
Hi! This is the case, the JavaScript actor will send a value to the entire output array. So even when you don't actively return anything you will still receive a value. The only solution at the moment is Comp for Trigger outputs and sending a 0 at all times.
What I do is the following;
- Create a variable in my main called response
- Set all the values to a default value that I'm sending. For triggers, this is a 0. For other values, this might be a loop through of my input vars, etc
- Alter the response array based on the code in main / other functions
- Return response array
I tried to create a User actor with some JavaScript inside it and do some quick test, but I could not repro the scene switching behaviours. What I could repro is the Activating scene issue that you are describing.
@DusX could you look into the attached Izzy file and let us know or this is behavoir that is expected ? Press 'r' to reset (or use the button in the Control panel) and use 'j' to jump to the next Scene. What we see is that in the counter / output we get a '1', should be zero. Since we didn't actively trigger it right ?
-
@Juriaan exactly. I tend to output booleans as a way to read a trigger. If 1 send trigger, if 0 don't.