I want to save previous values of modules for later use/comparisons, but so far without success:
- globals seem to be "read-only" from within a 'normal' module.
- the only internal variables I know of are "x" and "y". Abusing y to save a x-value fails for obvious reasons.
- trying to define a new variable inside the Expression modifier (like described in https://github.com/ArashPartow/exprtk/b ... readme.txt) results in a syntax error.
Am I missing something? Coding expressions would be way more intuitive if I either could define own variables, or even better create globals which are writable from within a module's expression. And from other globals of course...
Writable(!) variables
Re: Writable(!) variables
Variables may be practically unwritable, but you can assign values.
For example, this will 'compile' in an expression:
This code creates a variable and separately assigns a value and does return 5 when x > 3. You can't write to globals, but I've found that being able to declare read-only variables within the scope of expressions to be useful.
Local globals have been asked for before though I can't remember if making them writable has been discussed. What application do you have in mind? There is probably a workaround.
For example, this will 'compile' in an expression:
Code: Select all
var z1 ;
z1 := 5;
if (x > 3, z1, x);
Local globals have been asked for before though I can't remember if making them writable has been discussed. What application do you have in mind? There is probably a workaround.
Re: Writable(!) variables
Aaah...I've tried float, double and whatnot...that does the job. Thanks a lotSadler wrote:Variables may be practically unwritable, but you can assign values.
For example, this will 'compile' in an expression:[...]
A dynamic "Hold" function for modules which can be adjusted by the actual beat of a song. Right now "Hold" only accepts fixed values, and no matter how precisely I calculate this value it drifts away after some time...Sadler wrote: What application do you have in mind? There is probably a workaround.
Re: Writable(!) variables
It doesn't make sense for there to be variables that last more than one frame, because every frame is its own context and would keep overwriting anything you assigned more than one frame ago.
The thing that might be helpful for you to be aware of is the "xp" variable, which means "x previous" and is the x value from the previous frame. Thus you can compare the current value with the previous one.
The thing that might be helpful for you to be aware of is the "xp" variable, which means "x previous" and is the x value from the previous frame. Thus you can compare the current value with the previous one.
Re: Writable(!) variables
That's where writable globals would help, I could save context-information as long as I need it.Eric wrote:It doesn't make sense for there to be variables that last more than one frame, because every frame is its own context and would keep overwriting anything you assigned more than one frame ago.
Re: Writable(!) variables
Doesn't matter whether it's global or not, the same logic applies.
If I'm understanding correctly, what you want to do is have a global, and in that global, you do something like this:
Which means that if the condition is true, the global gets a new value (based on some function applied to the input, or perhaps just the input itself); otherwise, it gets its previous value, which means it stays the same.
If I'm understanding correctly, what you want to do is have a global, and in that global, you do something like this:
Code: Select all
if ([some condition], f(x), y)
Re: Writable(!) variables
Some pseudo-code for my "Hold" function:
Hold_Time could be dynamically computed in a global, but I see no way to remember Old_Time.
Of course this wouldn't be necessary if the Hold parameter of a module could be changed via a global and/or an expression
Code: Select all
if (Current_Time - Hold_Time > Old_Time) {
Old_Time := Current_Time;
x_old := x;
} else {
x := x_old;
}
Of course this wouldn't be necessary if the Hold parameter of a module could be changed via a global and/or an expression
Re: Writable(!) variables
Another way of saying what I said above is that you don’t assign a value to a global; rather, a global assigns a value to itself. Thus, if you want to save values for later, all your code should be inside one or more globals.