retreive value of named object in js?
I've looked in the docs and forum for an answer to this, but it clearly isn't straightforward. I have an object (a pictctrl) with a name that I'd like to retreive it's value from within a javascript.
for example it would be great if this worked...
var myobject = this.patcher.getnamed("Knob");
var myvalue = myobject.value;
post("myvalue is: ",myvalue);
but of course it does not. any suggestions?
peter
I'm ashamed to say, there isn't at this time.
jb
Am 14.08.2007 um 10:14 schrieb Patrick Delges:
> But I deeply hope there is some "get" or "value" message hidden
> somewhere...
ok, thanks for squashing my hopes :)
I ended up solving the problem by running the needed interface controls through javascript and handling everything there. In my situation it was a classic case of 6 of 1, half dozen of the other.
However, I do look forward to being able to arbitrarily and noninvasively poll an object for its value from a js!
P.
I seem to remember this was actually solved, and there is now a method for retrieving the value of a named object in JavaScript. I can't find it documented however - any hints?
P
Something like this will return the assigned scripting name of all the objects of the specified class in the patcher. The ".varname" bit is what you're after I think.
lh
function getname()
{
this.patcher.apply(eachobj);
}
function eachobj(a)
{
if (a.maxclass == "toggle")
{
outlet(0, a.varname);
}
return true;
}
eachobj.local=1;
hmm....ok. but I recall that, after the original admission by mr. bernstein, there was some simple addition to the JS object like
var btn = this.patcher.getnamed("myUIthing");
var thevalue = btn.getvalue();
or perhaps something like my first idea.
Oops I completely misunderstood. I thought you were after the scripting name of the object not its current value (ie "7" in a [number] object).
As a workaround you could always try connecting your ui object to your [js] and vice versa then sending a bang and setting a function list() to store the data that comes back in an array. The code below shows is a simpler example using [number].
lh
// grab.js
function msg_int(x)
{
post(x + "n");
}
function grab(tag)
{
var gnum = this.patcher.getnamed(tag);
this.patcher.connect(this.box, 0, gnum, 0);
this.patcher.connect(gnum, 0, this.box, 0);
outlet(0, "bang");
this.patcher.disconnect(this.box, 0, gnum, 0);
this.patcher.disconnect(gnum, 0, this.box, 0);
}
// EOF
Oh I've just read your very first post from all those moons ago and if what you're looking for can be set in the object inspector or by an attribute message then you can use getattr(). Taking your [pictctrl] problem as an example have a look below. Sorry for being a bit slow off the mark tonight!
lh
// getname.js
function getnameof(x)
{
myobj = this.patcher.getnamed(x);
outlet (0, myobj.getattr("name"));
}
// EOF
Some number-box somewhere has a name, the number-box has a value.
Given its scripting name, how do you find the object's value in js:
function getValue(name) {
return this.patcher.getnamed(name).getvalueof();
}