Strange pattr behavior with JS
I'm struggling with strange pattr behavior. It seems to me that it is common for both JS and visual environment.
I use pattr to store param value between sessions. I need pattr to load param and trigger JS init method. If param is equal to 0 (it wasn't initialized earlier) then its value is initialized and saved to pattr. Otherwise pattr value is used
As you can see, pattr triggers initVar method, but method fails to set pattr new value. When bang triggers initVar then all is fine
What can it be? A sort of loopback protection?
test2.js
Max Patch
Copy patch and select New From Clipboard in Max.
autowatch = 1;
inlets = 1;
outlets = 1;
var data;
function initVar(variable) {
data = parseInt(variable);
if (data == 0) {
data = 30;
post("data " + data);
this.patcher.getnamed('store_var').message(data);
}
}
Yeah, I imagine there could be a feedback problem there.
Max Patch
Copy patch and select New From Clipboard in Max.
This works.
Awesome, thank you!