Difference between revisions of "0x001C"

From SimsWiki
Jump to: navigation, search
m (Overview: Rewording per original entry)
 
(13 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{OldWikiEntry}}
+
{{Primitive
 +
|name=Run Tree by Name
 +
|opcode=0x001C
 +
|expansion=The Sims 2
 +
}}
  
=Run Tree By Name (0x001C)=
+
==Overview==
 +
This very useful [[Primitives|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.
  
Basically it runs trees by their name rather than their instance id.  The range that it can call trees is in the stack object, global, and the semi-global(maybe the object itself, although that would seem pointless). This is a very interesting and useful function.  It is the core of the phone plugin system, and is used to do alot of other things.
+
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 [[STR#STR.23|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)
  
==Overview==
+
[[Image:CallTreeCrossRef.JPG|frame|left|Calling object uses Call Name Tree strings in its own scope (i.e. same Group in this case, to find the function NAME]]
  
dd dd qq qq nn xx AA aa
+
<br clear="all"/>
aa BB bb bb CC cc cc uu
+
  
These are:
+
==Using the Instruction Wizard==
*d = unused in the sims 2.  In the sims 1, this would have been used to specify the string number(which was always strangely enough 303), however TS2 leaves them at 00 00
+
[[Image:RunTreeByNameInstructionWizard.JPG|frame|left|Run Tree by Name Instruction Wizard]]
*n = line id of string 12f(303) + 1
+
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.
*x = options:
+
:*0-run in my stack
+
:*1-run in stack object's stack
+
:*2-push onto my stack
+
*A (a) = data owner for parameter 0 followed by 2 bytes for value
+
*B (b) = data owner for parameter 1 followed by 2 bytes for value
+
*C (c) = data owner for parameter 2 followed by 2 bytes for value
+
*q = unsure of it's function. In TS1 this meant private or global, but in TS2, there are alot more values (although almost always 00).  I have seen it as 1d, 1e, 06, etc.
+
*u = appears to be completely unused
+
  
==Use==
+
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.
 +
<br clear="all"/>
 +
===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 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.
  
run in stack objects stack.  This is used in object interactions when you want to run a tree in your stack object remotely.
+
"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.
  
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.
  
=See also=
+
==See also==
 
*[[Primitives]]
 
*[[Primitives]]
 
*[[SimAntics]]
 
*[[SimAntics]]
  
[[Category:Modding]]
+
[[Category:Sims 2 Modding]]
 +
[[Category:Primitives|{{PAGENAME}}]]

Latest revision as of 12:25, 17 September 2012

Run Tree by Name
OpCode:0x001C
Game Version:The Sims 2


Contents

[edit] Overview

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)

Calling object uses Call Name Tree strings in its own scope (i.e. same Group in this case, to find the function NAME


[edit] Using the Instruction Wizard

Run Tree by Name 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.

[edit] 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.

[edit] See also

Personal tools
Namespaces

Variants
Actions
Navigation
game select
Toolbox