|Run Tree by Name|
|Game Version:||The Sims 2|
This very useful primitive allows you to write functions (trees) that operate on your object but that can be called from another object. Instead of running the funtion using its instance id as you would for a private function in the object, you instead run the function using its name. Itâ€™s quite a nice way to write them because the context of your object, i.e. attribute names are all correctly displayed in the call tree code and you also donâ€™t have to 'pollute' the calling object with code that is not really to do with itâ€™s object. It is also used a lot to provide objects of similar type the same named function to be called, but each providing a different implementation, or perhaps some defaulting to a semi-global implementation and others over-riding it as a private implementation.
The only thing the calling object needs is the ability to get the string name of the call tree from within its own strings (although semi-global will do) as shown in the picture. The call tree name strings are taken from Text List (STR#) resource 0x0000012F (see String Resources for all the different Text List usages). This will then run the BHAV of that name in the scope of the Stack Object (which may well be different)
Using the Instruction Wizard
The highlighted fields are for locating the string containing the BHAV name. The rest are for controlling where the BHAV is found in relation to the target (not caller), i.e. the Stack Object, and things to do with actually running it, i.e. passing parameters.
You chose (using Type) to run it in the stack for the 'My' object or for the current Stack Object ID. This means you get things like Temp variables for the stack you choose which can be particularly important when getting returned values.
More about Type
"run in My stack" is generally used in check trees. It will return false if no such tree is within range, or if it runs the tree by name, and the tree itself returns false.
"run in Stack Objects stack" is used in object interactions when you want to run a tree in your stack object remotely. This means that the My variable contains the value that is the Stack Object when the function is run.
"push onto My stack" treats it as if you are running that tree as a private function. This is generally used in the action tree of an interaction.
The choice between â€śrun on x stackâ€ť and â€śpush onto x stackâ€ť may be important if you hit the Check tree primitive blocked completion error.