messagename gets overwritten when anything() invokes itsself..

    Dec 30 2006 | 7:13 pm
    I ran into something I don't understand. It is hard to describe without many words (considering my poor english) but I'll try. You can also skip my description and go directly to the example below.
    Description: The javascript doc says messagename is "The name of the message to the js object that invoked the method currently running." Strictly speaking I'd expect the anything() function to have its own local copy of messagename. But since messagename is not a local argument of anything() but a 'global' property of jsThis, what happens if the anything method invokes itsself?
    From the example it looks like messagename gets overwritten, so that when anything() returns (to itsself), messagename is gone for the remaining part of function. The funny thing is, the inlet property behaves differently. It looks like this one is not overwritten but remembered as if it was a local property.
    Example: I know it sounds confusing, but have a look at the example and it will become clear.
    -------- Save as "test.js":
    inlets = 2;
    function anything() { if (messagename == "first") outlet(0, "next"); post("messagename " + messagename + ", inlet " + inlet); post(); }
    -------- Save as anything
    Expected output:
    messagename next, inlet 1 messagename first, inlet 0 OR messagename next, inlet 1 messagename , inlet
    Actual output:
    messagename next, inlet 1 messagename , inlet 0
    I hope someone can shed some light on this.
    Windows XP, Max 4.6.2

    • Jan 06 2007 | 9:42 pm
      This solution works! Thanks Joshua!
      Quote: jkc wrote on Sat, 06 January 2007 22:01 ---------------------------------------------------- > > On Jan 6, 2007, at 12:35 PM, Mattijs Kneppers wrote: > > > > > Still, if you want to try, you're more than welcome. If you find an > > alternative I'll definitly buy you a beer. > > Well, now that there's an offer of alcohol involved, I'm a tad more > motivated to think about the problem ;) > > I think that the following strategy works the way you wanted for your > initial example--i.e. copy the messagename and inlet properties to a > local variable. What happens internal to js is that messagename and > inlet are global to the script, set and overwritten with each message > call. Let me know if this doesn't solve your problem. > > test.js > ------------------------------------------- > > inlets = 2; > > function anything() > { > var mything = new String(messagename); > var myinlet = inlet; > > if (mything == "first") outlet(0, "next"); > post("messagename " + mything + ", inlet " + myinlet); > post(); > } > > > -Joshua > ----------------------------------------------------