Strange pattr behavior with JS

Jul 27, 2010 at 9:38pm

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
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);
}
}

– Pasted Max Patch, click to expand. –

[attachment=137675,876]

Attachments:
  1. screenshot.jpg
#51536
Jul 27, 2010 at 10:56pm

Yeah, I imagine there could be a feedback problem there.

This works.

– Pasted Max Patch, click to expand. –
#184856
Jul 28, 2010 at 12:22pm

Awesome, thank you!

#184857

You must be logged in to reply to this topic.