Constants?

Is there a recommended way to do constants in VL?

When I have a simple constant (just a value) I’ve been creating a utility operation for it, eg MASS operation that just contains an iobox with a float, and calling that operation everywhere I need it.

But now I’ve got constants that are magic numbers derived from complex formulas.
-I could manually copy the results to ioboxes as per the previous method but this isn’t convenient if I want to change the parameters of the function that generated them before the next compile. Also If I publish this as a contribution I think that could be a bit confusing
-I can invoke them on create and store in a pad but I have thousands of instances of the object in question. To have a local pad version of the constant unnecessarily increases the memory footprint of each object.
-I can create inputs for the magic numbers on the operation that needs them and call them from the parent patch (or even make a special object for the magic numbers that only generates them once) but this creates a lot of visual mess for what’s pretty simple.

Is there a more convenient way?

Ideally I’d be able to turn a utility operation into a real constant that’s only calculated on compile and just referenced after that.

hello toby, you can use the Singleton (experimental) nodes for that, you only need to take care that you have a unique type for your constants. for example a Record MyConstatnts with a Get operation for each constant, that you set as data. then wrap convenient util Operations around the singleton + getters and output the individual properties of your type. this allows you to have only one instance of the constants record.

image

image

Constants.vl (16.1 KB)

1 Like

Nice. I knew y’all would have thought of something.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.