0x0032
Add/Change the Action String | ||
---|---|---|
OpCode: | 0x0032 | |
Game Version: | The Sims 2 |
Contents |
Overview
This is a very powerful primitive which allows pie-menus to be built based on run-time decisions. You can, for example, in your Guardian BHAV (which is run before the pie-menu is displayed when you click on an object) use this instruction to dynamically build a menu.
Using the Instruction Wizard
Add/Change action string mode
The strings used by this instruction are taken from Text List (STR#) resource 0x0000012E (see String Resources for all the different Text List usages). You can either provide the specific string to use, or instead provide the number of the string in Temp[0] prior to calling this instruction (quite handy given the way parameters are passed to the action interaction function (see below). One thing to note about this is the number in Temp[0] is one more than the string number, i.e. it’s the same number as shown for the string when you choose it from the pick list.
This instruction is often used in combination with the Set to Next (0x001F) primitive which makes it easy to loop round at set of related objects/Sims and make a menu for each one that is suitable for the menu. It is very important when doing this to remember to return True at the end of the Set to Next loop if you have found any items, and only return False if you find none. This is perhaps different from the normal return you would do from Set to Next so bear it in mind.
When you click on one of these dynamically added menu strings, how can you tell what was clicked?
Well, Param[0] to your action interaction function contains the Stack Object ID which was set at the time of using the Add/Change the Action String instruction. Since this instruction is often used in combination with the Set to Next (0x001F) primitive, which will be used to set the Stack Object ID to the next instance of something, you almost get Param[0] for free without realising!
Param[1] to your action interaction function is whatever was in Temp[0] at the time of using the Add/Change the Action String instruction (which could be your string index if you use the instruction in that way (see above)).
Change icon mode
Never used this - anyone else able to fill in this section?
Examples
This primitive is used in the guardian to either change the name of the interaction in the pie menu, or add options via plugins. Basically it sets the menu option for whatever the stack object is in the check tree of an interaction.
This works the same as in TS1, except that you no longer have to specify the string 302, or 12E(Hex) for the string used. This primitive automatically references to the text reference 12E, and the id of this string is in operand 04(remember that 01 will mean id 0, 02 would be id 1, et. al.).
Here is an example where it just changes the name of the menu option depending upon age:
(Interaction - Use - Test)
0:My Person Data Age > 18 1,2 1:Add/Change Action String:0(0x32:00 00 00 00 01 00 00 00 - 00 00 00 00 00 00 00 00) true,error 2:Add/Change Action String:1(0x32:00 00 00 00 02 00 00 00 - 00 00 00 00 00 00 00 00) true,error
Because the stack object by default in a check tree is the object that the sim is interacting with, this will just change the pie-menu option for using this object.
However Set-To-Next-Loops can provide a whole new usage to this function. In this example, I will show how multiple stack objects can add menu options to a single object. This is very useful for making patches that allow for plugin upgrades, so that anyone can add to your patches without conflicts. Here is an example of a basic Set-To-Next-Loop with menu options automatically being added:
0:Local Var 0 Assign to: 0 1,error 1:Local Var 1 Assign to: Stack Object ID 2,error 2:Stack Object ID Assign to: 0 3,error 3:Set to Next(object) 4,7 4:Run Tree By Name:(CT - My Object) 5,3 5:Add/Change Action String:0 6,error 6:Local Var 0 Assign to: 1 3,error 7:Stack Object Assign to Local Var 1 8,error 8:Local Var 0 Equals: 1? true,false
in this case, CT - My object would be a string in the text list 12f using the Run Tree By Name primitive, and thus would search for any object that had a behavior function with that name in it, and because it would be a new stack object, it would not change the name of the interaction, but add the menu option with the specified string in 12E of the id defined in operand 04 of the primitive(remember that 01 will mean id 0, 02 would be id 1, et. al.)
Note: The object id of the menu object selected from the pie menu will be stored in Parameter 0 of the action tree.