BHAV:Build pie-menu

From SimsWiki
Jump to: navigation, search

Contents

Overview

Here we show a SimAntics BHAV code snippet that will build a pie-menu to reference each person found on the lot. It loops round looking for a person and builds the pie-menu string for that person before moving on to the next person in the loop.

Illustrating

This code snippet illustrates several primitives. Use these links to see full details about how to use these primitives in order to recreate the BHAV code below.

The pie-menu string resource

Before we write the BHAV code, we should put in place a string to use in Text List (STR#) resource 0x0000012D (see String Resources for all the different Text List usages). For this example we are going to assume a string exists on the very first line (line 0) which contains "Wave at.../$Object". The text following the '$' is a String Substitution which is a very handy trick when doing exactly this sort of thing.

The BHAV code

Preparatory steps

Firstly we start by zeroing out the Stack Object so that our loop through all the people starts from the beginning.

0x0000: Expression (Stack Object ID := Literal 0x0000), True Target: 0x0001, False Target: Error

Then we set up our Local variable which we will use to remember whether we have found any people in the loop.

0x0001: Expression (Local 0x0000 := Literal 0x0000), True Target: 0x0002, False Target: Error

The Loop

Now we begin our loop round all the people.

0x0002: Set to Next (Stack Object ID, person), True Target: 0x0003, False Target: 0x0005

If we find someone, that is our Set to Next instruction returned True, we will remember that fact by setting our Local variable to 1.

0x0003: Expression (Local 0x0000 := Literal 0x0001), True Target: 0x0004, False Target: Error

Then we build the pie-menu string for this person we have found. The person's object ID will be stored in the Stack Object which the string "$Object" replaces with the name of the thing (in this case person) found in the Stack Object.

0x0004: Add/Change the Action String ("Wave at.../$Object"), True Target: 0x0002, False Target: Error

After this instruction we loop back round to the Set to Next instruction to find the next person.

After the loop

Once we have exhausted all the people on the lot, the Set to Next instruction will return false and will jump to this instruction where we test whether we have ever found any people at all, and if we have (i.e. our local variable contains the value 1) then we can return True, to indicate the pie-menu is good; otherwise we return False which stops the pie-menu from calling it's interaction. Oddly, returning false here would still display the pie-menu, if we had built one, but wouldn't drive the interaction behind it.

0x0005: Expression (Local 0x0000 == Literal 0x0001), True Target: True, False Target: False
Personal tools
Namespaces

Variants
Actions
Navigation
game select
Toolbox