Javascript Enable Nodes?

Is it possible to set enabled from javascript?
what are the best practices with set envelope vs set float?
Whats the best way to turn a float into a int, I’m currently getting a value back after setting it from a slider, the value I’m setting is an int, (count on a cloner) and I want to use that int in soem maths, seems wierd to get it after setting it to turn it into an int, I did try ~~ but that was getting an int with different mapping from the actual count, also I dont have a ~ key :wink:
There isnt much documentation of javascript, I’m guessing thats the way to have one value control several different parameters in different nodes, or am I missing any other ways?

Hi, here is some info from my experience so far.

You cannot enable or disable with javascript - but you can control the value of an ExecuteChildNodes node (value of 0 prevents connected nodes to this node from executing). However be warned that ExecuteChildNodes does not seem to work with Particle Affectors (and perhaps others, but I’ve not tried them all).

I find SetEnvelope unreliable, but most of the time I am in GUI mode, it may behave more consistently in Standalone. However- if you are controlling many nodes with SetInt/Float etc the GUI updates will have a strong affect on CPU performance. These go away in Standalone.

In JavaScript there are many ways to convert a float to int - Math.floor( floatvalue )/Math.ceil( floatvalue )/Math.round( floatvalue ). They each work a little differently, so look them up.

To your last point, JavaScript is probably the most effective way of addressing the values of many nodes at once, especially when you are setting parameters that cannot be attached to incoming ports. You’re right, there’s not much documentation, but that’s mostly because there aren’t many Notch specific methods included. It’s also not super clear how efficient the JavaScript processing is, but I am currently working on a project which has hundreds of lines across multiple scripts being executed in the update loop, and performance is manageable.

1 Like

Thanks for that, I did try Math.floor etc, but I got errors, it might be math vs Math, as my dyslexia sometimes has me missing capitalisations!
The excute child doesnt work with Effector either it seems! I was hoping to make a generic block with some different effects to switch between, and save some ticks while particular ones are not in use. Maybe a state machine will do it…


Well that doesnt seem to work, both states are active!

Yeah, I abandoned the inbuilt state machine pretty early on and wrote my own in JavaScript. I also noticed it could not enable/disable certain nodes. With some intensive nodes you can input a bounding box, what I have been doing is making the box very small when I’m not using the effect, this helps things like the Flocking Particle Affector from sucking up resources. If you’re lucky changing the radius of the effect you are working with might have the same effect.

1 Like