I hope someone can follow this, cause it’s driving me nuts. I’ve stripped the problem down to the essentials:
- Here is my node script…very simple. Each node contains a reference (to a button in interface bulder) and a list of child nodes:
on node(theObjectReference, theList)
script node
property theParent : theObjectReference
property theChildren : theList
end script
return node
end node
-
I have hard coded my tree. It’s big. It has a lot of object references (ie. button “myButton” of tab view item “myTab” of tab view “myTabView” of window “main”). They are all correct…I tested each one individually.
-
I have a global called root, and a function called initTree(). This function is where the global variable is initialized to my hard coded tree.
-
I have a search function. It’s job it to find the matching object reference (when a button is clicked) and return the list of its children.
on searchTree(theButton, root)
set children to theChildren of root
--make comparison
if theParent of root is equal to theButton then
--found it
return children
else
--loop over all children
repeat with child in children
--recursive search call
set foundChildren to my searchTree(theButton, child)
--if it was found in child, propogate it up the stack
if foundChildren is not equal to {} then
return foundChildren
end if
end repeat
end if
--not found, return null by default
return {}
end searchTree
- The problem. It doen’t work…quite. A few things to know:
- some things I search for are found correctly always
- the first thing I search is found always, every time I search for it
- some subsequent searches for other items are not successful
- (ex. if I search for A, then B, it will find A but not B. If I run it again and search for B, then A, it will find B but not A. In both cases it will find C)
-
If I call initTree() before I search each time, then the search ALWAYS works, for EVERYTHING I search for, so the tree/function are right at the start.
-
So what the heck? Am I mutating the tree by calling search? I think not, because if I print out a label for each node I visit, the tree is the same each time, and every node is always in the right place. Nonetheless, the REFERENCE stored in the node seems to fail. If I try the line of code
log title of (theParent of the child) as text
to print the title of the button referenced by each node in the tree, the references that aren’t found by the tree also yield a “NSCannotCreateScriptCommandError (10).” This, of course, despite the fact that if I hard code this statement for every reference in my initial tree, it works.
HELP! (please and thank you) I’m going nuts on this one.