Auto/Manual scripting name

    Aug 19 2010 | 7:19 pm
    Hi Maxers,
    I have an interesting problem to solve here. It's about changing the scripting name of a subpatcher/bpatcher/abstraction again with JavaScript.
    I have written a small script to automatically name a subpatcher/bpatcher/abstraction. If I give an argument ton my JS object containing this script, it sets the varname of the patcher its contained in. That's pretty easy, you can find a lot of example for that on Cycling's Forum. I also added some easy but neat features like : if you bang it, it outputs the current varname. If you send it the message "parent" and the subpatcher/bpatcher/abstraction is actually loaded in something that has a script name, then it returns that name. Of course, if I don't give any argument to the JS object, it does nothing when loaded. But you can set the name afterwards with a "set" message.
    Anyway, this is rather handy.
    The problem is this one : Imagine you have a bpatcher (for example) with this JS script inside whith an argument, it will auto-name the bpatcher every time it's loaded. Now, if the user (I mean the person who added the bpatcher) wants to change the name "by hand" he/she can do it in the inspector of the bpatcher. However, this "manual" change won't actually stay, even if the person saves the patch. Why ? Because next time it's loaded, my script is going to rename the bpatcher with the argument it has. I would like to avoid that, meaning, if the person decide to change the scripting name, then it overrides the auto-naming. And of course, I would like that to be automatic (ie. without needed to open the patch where the JS is). Is it clear ?
    I have no idea how to do that. The first thing is to detect that a "manual" naming occurred. Is that possible with JS ? Second, the JS has to permanently stop renaming once it detected that. It could be simply by destroying itself (is that possible ?). Or inhibit the auto-name in a way ? Or change it own argument ?
    I though you, Maxers (and JS nerds, at least for some of you) might have some idea about this...

    • Aug 20 2010 | 12:18 am
      I use a pattr with an initial of -1 to set the state of whether a js has already received data initialized by the user. If the js has already been initialized, and saved in a former patch, its value will have been incremented (by some js logic) to a higher number. This wasn't exactly easy to figure out, and I don't have an example to show you right now, but get back to me if you need one. The system should work for your purposes, as I'm doing something fairly similar.