This code works:
$MyString=$Name;
$Path(children).each(x){$Name(x)=$Name(x).replace(“NN”,$MyString)}
The idea is you have a parent note that has some child notes that each have in their names the string ‘NN’ and I want to replace that part of the string with the name of the parent. So if I stick that in an edict, it runs fine.
However, I don’t want it hanging around because I need this done just once, when I create the parent note which inherits the child notes from its prototype. I create the note, setting the name at the time of creation. So, I put my code in this:
if(!$isPrototype)
{
$MyString=$Name;
$MyList=$Path(children);
$EdictDisabled=true;
$MyList.each(x){
$Name(x)=$Name(x).replace(“NN”,$MyString)};
}
The idea is that the parent note is created, inherits this edict, in an enabled state from its prototype, it runs exactly once and then is disabled. (I don’t want it running on the prototype all the time, hence the conditional.)
I’ve played around and played around with this and as soon as the .each loop is in the if conditional, the values that x takes seem to vary, and some operators work and some do not. It is as if the if conditional changes the scope or namespace in some way I do not understand.
Help, please. I’m open to doing it another way, but I’d also like to understand if there is some scope change with if() that I do not understand.