Entry Level Hacking - WEEK 4: Adding New Behaviors and Menu Options

Author: Grapholina


Hello, everyone! I think by now most of you are comfortable with my quirky way of teaching, so I'm going to push on, moving you in a rather speedy way towards a few items that are really more on the Intermediate level, but which I feel you are ready to handle.

LESSON OBJECTIVE

  •  Starting a Code Book
  •  A Brief Look Into Functions and Placement
  •  Adding a New Interaction to Our Chair
  •  Adding to Our Chair's Menu
  • Another Way of Adding Moods

This week we're going to add to our chair a quite unrealistic behavior and interaction. We will give the Sims the choice to set their lovely chair on fire. By doing so, we will learn a new function, and we will explore placement. Functions and placements are two factors we will explore in detail once we get to the Intermediate Level classes, and since this is our last Entry Level class, I felt it was a good jumping point.

THE CODE BOOK

Every hacker has in one form or another, a Code Book. We build our own Code Books depending on our needs and on how we like to work. Today, you will start to build your very own based on mine. After it is all said and done, you of course, are free to change it up any way you want.

I use a sturdy and large 3-ring binder, sectioned off with tabs, and an index table for quick access to sections of code I have acquired. One of my tabs is "Functions".

FUNCTIONS

We've dealt with functions before. Every time you looked at your Data box, you've had to deal with a function of some type. There are 4 types of functions, and they are:  Expressions, Privates, Semi-Globals, and Globals.


Fig. 1.1

The Private Function depicted in Fig. 1.1 above (4111) is the "ComeAndSeeMe" behavior found in our chair. Remember that one?

You can get a binder later. For today, you will pull out your notebook, and write this code down under the heading of "Functions":

Function 42: Create New Object Instance

Everyone write that down? Function 42 is a nifty one which we will work with this week.

What does it do?

When a child walks up to the bathroom sink to wash his hands or brush his teeth, Function 42 comes into play right away. It produces the step stool for the child to climb onto. It produces the toothbrush and toothpaste for the child to use.

When a Sim walks up to the easel to paint, Function 42 puts a palette and paintbrush into the Sim's hands.

When a Sim reaches for a plate of food from the meal that has been served and walks away with his own plate of food in his hand — that's Function 42 in action.

Let's experiment a bit with functions. Open IFF and bring in your chair. Select BHAV, and then double click Behavior #4110 "init Very Expensive" to open it. We are only exploring, so please do not save anything we do unless I ask you.


Fig. 1.2

The behavior we just opened has nothing to do with this lesson. We opened it only as a place to work in. Right mouse click anywhere and select "Add" from the menu.

The new line we just added is IFF's version of a "blank" line; and unlike in SS, where the line would display "idle", meaning it is empty, IFF puts attribute calls in the line. Other than that, this line comes equipped with very little else.


Fig. 1.3

The Line's corresponding Data box is a "standard" one.


Fig. 1.4

Right now, it is showing us Function 2 which happens to be an Expression function. IFF has one very useful button in the Data box, and it is that little button with the three dots inside, found to the right of our function number. Click that button now.


Fig. 1.5

The button you just clicked is called the "Function Selector", and once you click the button, you will get a little box that looks like this, showing you that the number 2 for Function is an Expression.


Fig. 1.6

The box depicted above is where you are allowed to select any function available to the object you are working with. In other words, our chair has several functions available, and you can find them all from this box. This does not mean that we cannot add more functions. It simply means that this box will display ONLY what is available. If we add another function, the little box will show us that function as well. Does everyone understand this? If not, please let me know, and I will work with you until you do. Understanding functions is imperative! You must understand this lesson before you proceed to the Intermediate level.

Very well, then. To the right of the word "Expression" is our pull down menu. Click the arrow now, and you will get all the available functions for our chair.


Fig. 1.7

Go ahead and scroll through the menu. You should see the different types of functions available to the chair, such as Globals and Privates.


Fig. 1.8

Private funtions (or calls) are always functions found locally within the object itself. Look at the private calls here, and compare them to the ones found under the BHAV tab. They're the same, aren't they?

Any time you are working with an object, it is a good idea to use the time to build up your Code Book. Let's add a few more functions to your Code Book right now. You should still have the Select function box open. If not, pull it back up and make sure it looks like this:


Fig. 1.9

Use the pull down menu, and then scroll until you find this Global function (Create Stool):


Fig. 1.10

After selecting the function, click "OK", and then look at your experimental Line 6:


Fig. 1.11

Then, look to the right at the corresponding Data Box:


Fig. 1.12

Notice how your Function changed from a 2 to a 383? Open your notebook to "Functions", and write this down:

Function 383 (global):  Create Stool

Ordinarily, I would also include a description of what the function does, but this one is pretty much self-explanatory, so I would leave it alone.

Go ahead and add as many functions to your Code Book as you wish.

Now, we'll work with Function 42: Create New Object Instance. Still working in the same Data box for experimental Line 6, type the number 42 into the Function line.


Fig. 1.13

Notice that your Line 6 has now changed to reflect the Function number you inserted, and it now reads "Create New Object Instance.


Fig. 1.14

And you will also notice that there are other descriptive words enclosed within the parentheses after "Create New Object Instance). The words inside the parentheses tells where the new object will be created. Place in front of me is, of course, telling the chair where to place the new object (a sim) — in front of me (the chair). I know this can get confusing; however, right now it is not terribly important. Eventually you will get the hang of it.

Let's go back to the Data box, and try something else. Get rid of the "1280" in Parameter 3 by inserting the number "1264" in there.


Fig. 1.15

Your Line 6 changed and should look like this one:


Fig. 1.16

Notice the difference in the words contained within the parentheses? Since this particular function is a bit ahead of the Entry Level classes, I won't go into details now, but in future classes we will fully cover neighbor in stack object and placements.

Going back to the Data box, get rid of 1264, and type in the number zero (0).


Fig. 1.17

Look at Line 6:


Fig. 1.18

Quite interesting, isn't it? Instead of stack object or neighbor, we have our friend, the GUID! And that, folks, opens up a whole lot of opportunities for us. With this little bit of code, we can have our nice chair create all sorts of things — providing we have the "thing's" correct GUID. Very cool, indeed!

After the GUID number, which in the case above is currently blank, there is a placement instruction (place in front of me). We can change that. We can have the chair create something and place it wherever we want, or a random available place. The game is quite smart, though. If you ask the chair to create something and place it at a specific location, and that location is occupied... the game will find the next closest available spot and place it there (if coded to do so).

Back to the Data box! Go into Parameter 3 and experiment typing numbers in there. Not big numbers, though. Start with the number 1 and see what your line says. Then type in a number 2 instead, and so on. You'll be amazed at where you can have the chair place the object it is creating, and hopefully will also give you ideas for creating an object (which you will do for your final assignment). Keep your Data box open when you're done experimenting with Parameter 3.

* * * * * * * * * * * * * * * * * * * * *

The next function we will look at is Function 16. If you previously did not add it to your Code Book, enter it now:

Function 16: Find Location For

Function 16 deals with placement, and usually (but not always) works hand in hand with Function 42, paticularly when Function 42 has created the object "out of world". Creating an object "out of world" will create it "off screen" (hidden off to the side where neither the player or Sim is aware it exists) and Function 16 is used to then place it on the lot. During our Intermediate classes we will use this quite a bit.

Type the number 16 in the Function Box, and make sure that your Parameters all read ZERO.


Fig. 1.19

 

Function 16 gives you:


Fig. 1.20

Once again, we see our Function name (Find Location For) and then the placement instructions after it. Shall we experiment again? Sure! Why not?

This time, you will enter numbers (starting with 1) in Parameter 1. Go ahead and try as many as you like, and if you run across an interesting one, jot it down in your notebook beneath your Function 16 description. It'll come in handy later on.

Functions are fascinating and we can stay here studying them for at least a hundred more pages, but we won't. We'll stop right here, and get back to work on our chair. When you are done experimenting with Function 16, click the CANCEL button (not the OK). This will not save any changes you've made while playing around in the behavior, and take you back to the main screen in IFF.


Fig. 1.21

CREATING A NEW BEHAVIOR

Note:  Make sure you have a good copy of your cheap chair safely tucked away before starting this exercise.

You should already have IFF open, and your cheap, but very nice chair already in it. Right click anywhere in the white, and select "Add" from the menu. When the Add Item box comes up, you are going to fill it out accordingly.

• We are adding a new Behavior
• The ID number will be one that isn't already in use
• The name of the behavior will be appropriate to the function. Fire in this case

Does your box look like this? The name can be different, but the rest should look like mine.


Fig. 1.22

Click OK, and take a look to see if your new behavior is there:


Fig. 1.23

Good. Write the behavior #4115 "Burn" in your notebook, we'll need it later when we are away from this screen.

The Burn behavior we just created is empty. Double click to open it, and let's fill it out.

Right click anywhere in the window and select "Add" from the menu, so that you end up with one empty line:


Fig. 1.24

Select Line 0, and then move over to the Data box. Fill the boxes so that your Data box matches mine. Every time you enter a number, watch Line 0 to see how the number you entered affected the line.

Although Parameter 3 can be changed to specify location, you shouldn't mess with it at this time. It can cause some nasty results.


Fig. 1.25

Does Line 0 look like this?


Fig. 1.26

The information we entered into the Data box (shown in Fig. 1.25) warrants explanation. Last week we covered GUID's. Today, we'll recap and go a step further by explaining HOW to enter the GUID numbers so that the game can read them correctly.

Take a look at the GUID shown in Line 0:  24C95F99

That happens to be the name for FIRE in Hex. I know it is because fire is an object. A global object, and I looked it up in one of the global files and got the GUID number from it so that you wouldn't have to go to all that trouble. Am I just so nice, or what?

Anyway, a good way to simplify matters for us, is to break the GUID down into segments that we can easily "see", such as:  24  C9  5F  99  (4 sets of 2, and each set always stays together exactly as you see it).

Now comes the important part. Unlike Script Station, IFF does not like it when you enter the GUID number just like that. So, to appease IFF, we must first reverse the order of the numbers before we can enter them. Take a look at my example below, and again, if you do not understand this, PLEASE let me know so that I can clarify things for you. We will NOT go into another explanation in future classes.


Fig. 1.27

Why do we have to do this? Because unless we are HEX wizards, or have a fangled dangled Hex calculator/converter handy... we use the HEX parameters boxes at the bottom of the Data box to enter our GUID numbers in their correct reversed order.


Fig. 1.28

As you can see, each set of 2 stayed together. When we enter the GUID in this manner, IFF then translates the Hex numbers and enters them for us into the correct Parameter boxes. Let's take a look at that now.

Study the following diagram for a moment, if you will.


Fig. 1.29

The previous picture shows how IFF took the HEX numbers of the GUID and translated them into decimal numbers to be inserted into Parameters 1 and 2.

Let's redo the Data box so that you can see it in action. DELETE the numbers in Parameter 1 and Parameter 2 by inserting a ZERO in each box. IFF doesn't like it if you leave something blank.


Fig. 1.30

Keep an eye on Parameters 1 and 2 as you type!

• Into the first HEX box, type 99
• Into the second HEX box, type 5F
• Into the third HEX box, type C9
• Into the fourth HEX box, type 24

See how IFF translated for you as you entered the numbers? Great! Make sure your Data box looks like it should, and then we'll push on:


Fig. 1.31

That's it for our "Burn" behavior. Next on the agenda is to create a new menu option from which to call up our new behavior.

Click "OK" to get out of Behavior #4115, and get back to the main screen.

CREATING A NEW MENU OPTION

Select the TTAB (Tree Table) section, and then double click "Chair - Dining - Cheap tree table".

Click the "Add" button under the Interaction items box:


Fig. 1.32

Doing so will give you a new line: #1: New Item. We need to give "new item" a better description, so go over to the right under "Properties" and replace "New Item" with "Burn".


Fig. 1.33

Next, we fill in the Action and Check tree numbers. Our Burn behavior is #4115, so we enter that number into the Action tree # box, and since we don't have a Check tree #, we leave the zero in there. We don't have a check tree because there are no conditions to be met for the fire to be created. This is one of those "do it and don't ask any questions" situations.


Fig. 1.34


Click the "OK" button when you are done, and then SAVE and EXIT IFF.

Time To Test

Your chair should create a fire on demand (by choosing "Burn" from the menu), therefore, make sure you're testing near a smoke alarm, or with a Sim who isn't so lazy he will not extinguish the fire on command.

You should also test burning the chair while a Sim is sitting in the chair. The way we've positioned the fire being created should give the sitting Sim the opportunity to quickly jump out of the way. (Unless he's a sloth.)

So, keep your fingers crossed, and let's hope everything works as intended. If the Burn interaction does not work properly, STOP and ask for help before proceding.

VARIABLES, PARAMETERS, ATTRIBUTES & CONSTANTS

We are going to break off from working on our chair to take a look at variables, parameters, attributes and have a little refresher on constants. This is a bit of information that will come in handy later on and it is quite okay if you don't "get it" right away. As long as you have this information, somewhere down the road when we encounter them in objects, things will begin to click.

Variables

Local Variable:  This one is perhaps the easiest to get confused on. A Local Variable are called such because it is found in the behavior where it is mentioned and affects only that behavior. If you were to insert a new behavior to be run from the behavior where the Local Variable exists, the new behavior would not be affected in any way by the variable.

The number of Local Variables being used within a BHAV must be declared in the BHAV's header, the window frame to the upper right in the Behavior editor.


Fig. 1.35

Temporary Storage:  This is a very useful variable. It's availble to all BHAVs in the object, and even to other objects. The only drawback is that once you exit the game, all data stored in a Temporary Storage container disappears and the original values are returned. A good example is when a Sim picks up something to carry — like a plate to the dishwasher. There are no header boxes to update, so you need to make sure you keep track of what variable is stored in which Temporary Storage area.


Fig. 1.36

Attributes:  Unlike Temporary Storage above, where the information stored is deleted upon exiting the game, the values stored in Attributes will remain. Any information you need saved with the game (which channel the television is on, the book a Sim is reading, a purchase made on a community lot, etc) would be stored in Attributes.

Each attribute stores one numerical value, and the value can represent just about anything. An example is when you go into a Community Lot to purchase something... say, a dog collar. You walk up to the collar stand and you "Buy a blue dog collar". The attribute was set by Maxis to 1. But you could easily go in and fix it so a player can buy more than one item at a time.

Here's an example from one of the stands where Sims can purchase items. Notice Lines 14, 15, 17, and 18. Maxis had it so that the Sim could buy 1 of this and 1 of that. Then, look at line 16. I changed it so that the Sim could buy 20 of that particular item. Line 20 could be referring to magazines, dog collars or carrots. It doesn't matter.


Fig. 1.37

Parameters

Parameters:  Parameters are not variables. They are bits of information used to tell the object how to behave. You've seen them often enough. When you look at the Data Box for a statement within a behavior, the numbers in the boxes Parameters 1 through 4, thats bits of information being passed as parameters/boundaries.

These bits of information can be passed to other behaviors when it is run as a statement or a private. If values have not been assigned to the parameters of the [priv] statement (In other words if you have entered -1 in all four parameter fields AKA ff in all 8 hex boxes) they will inherit the values of Temp Storage 1 through 8.

Like Local Variables, Parameters must be declared in the BHAV's Header frame in the upper right hand corner of the Behavior Editor window

Constants

Constants:  Constants are numerical values stored within an .iff file itself. They're read only, so unlike the variables their value does not change as the program is run. Constants are stored in the BCON section (resource) of an object. We can add to the Constants already found in the object, we can modify the existing ones, or we can delete them; and indeed, Constants are the easiest to work with.


Fig. 1.38

A NEW WAY OF ADDING MOODS

Earlier we added hunger to the chair by linking the mood to our existing comfort lines. As some of you might have noticed, bladder decreased as hunger increased. We will now attempt to balance things out by injecting a bit of "bladder" into the chair in a completely different way.

Open IFF, and bring in the cheap chair. Go into the BHAV section; we want to place the bladder increase at the correct point of action, and the correct point of action, logically speaking, should be while the Sim is sitting and before the Sim gets up from the chair. It wouldn't do at all if bladder increased after the Sim rose and left the vicinity of the chair. Or before he sat down.

Find Behavior #4099 "Sit Core". If you'll think back to earlier lessons, that is where your Sim is instructed on how to enter the chair for sitting. It's the long and yucky behavior, so right click anywhere in there to "rewrite" the lines of code.


Fig. 1.35

Earlier we added hunger to the chair by linking the mood to our existing comfort lines. As some of you might have noticed, bladder decreased as hunger increased. We will now attempt to balance things out by injecting a bit of "bladder" into the chair in a completely different way.

Open IFF, and bring in the cheap chair. Go into the BHAV section; we want to place the bladder increase at the correct point of action, and the correct point of action, logically speaking, should be while the Sim is sitting and before the Sim gets up from the chair. It wouldn't do at all if bladder increased after the Sim rose and left the vicinity of the chair. Or before he sat down.

Find Behavior #4099 "Sit Core". If you'll think back to earlier lessons, that is where your Sim is instructed on how to enter the chair for sitting. It's the long and yucky behavior, so right click anywhere in there to "rewrite" the lines of code.


Fig. 1.35

After the lines are re-written, we can read them easier, and you should be able to scan through until you find your beginning point which is your chair's GUID number. Mine is on line 15. You should see your GUID there.


Fig. 1.36

Notice the line jumps to Line 16. Let's follow the trail to where the function ends for our chair. Follow closely, because there are other chairs involved here, and we don't want to add bladder to any of those.

Line 15 jumps to Line 16, and that line instructs the chair as to which sound to play when a Sim sits (depending on the type of chair: metal, wood, etc.).


Fig. 1.37

We then jump to Line 9. Line 9 is instructing the Sim from where to enter the chair (entry flag 1 means from the front). Line 9 then jumps to Line 10.


Fig. 1.38

Line 10 is instructing the Sim to be animated, and then jumps to Line 11.


Fig. 1.39

When inserting bits of code into existing code, you should always make certain of where you are in the code. For all you know, this animation could be instructing your Sim to be sick or something, and therefore this would not be a good point to insert the add bladder command. Before we go to Line 11, let's stop here and check out the animation id 1 from object, to see what that is. "From object" means the animation is built into the object and not being called from a global outside the object.

Click "OK" to get out of the Behavior, and let's go over to the STR# section. Double click #129: "a2o" to see what our id 1 means.


Fig. 1.40

Looking at ID 1 tells us the Line of code over in the BHAV section is telling the Sim to sit, entering the chair from the front, in accordance with the previous line of code (entry flags). So this tells us the Sim isn't yet sitting. Not a good point to add bladder, is it?


Fig. 1.41

Very well, then. Click "OK" to get out of the window, and let's go back to BHAV, #4099, to continue following our trail. We were about to check out Line 11. Find it, and let's take a look.


Fig. 1.42

Starting with Line 11: The line says to reset the animation. We can only assume that the Sim is sitting at this point (resetting "sit"), and then jumps to Line 12.

Line 12: Snap is a funny command. Have you ever watched a Sim sitting in a chair, and then he makes a move as if to get up, but then appears to think twice about it and settles back into the chair? That's a snap. A snap is also when the Sim leaves the comfort of the chair. He snaps out of the animation for sit.Snap can be used in many ways. Line 12 jumps to Line 13.

Line 13: The Break Point. Meaning: That's it, end of routine. See how the Line ends in True/Error?

Alright then. We don't want to inject bladder increase at the point of snap or the break point. Therefore, the only logical place available to us is right after Animate Sim (reset).

Let's do it. Right click on Line 11, and select "Duplicate" from the menu. We are selecting duplicate, because the return lines will already be in place (12, 11).

Now we have a total of 35 lines of code, with our duplicated line being #35. Click Line #35 and let's modify the Data box for the Line.


Fig. 1.43

We want Line #35 to read: my motives Bladder += 40. Any more than 40 and you'll have a problem trying to keep your Sim out of the chair. But you can experiment later, if you feel like it. Make your Data box look like mine:


Fig. 1.44

Let's go over the Data box, to make sure we understand what we've done.

Function: 2  Is an expression ( my motives ) that will be defined by Parameters 1 through 4.

Parameter 1:  Defines the mood, in this case 9 for bladder.

Parameter 2:  Defines how much of Parameter 1 to inject. We say "inject" because unlike the hunger mood we tied in earlier, where it increases gradually up to a certain point, this one is a one time shot when the Sim sits. Everyone understand this?

Parameter 3:  Tells it to ADD. 768 = Add. You might want to write that into your Code Book, probably under a heading of "Parameters".

Parameter 4:  The 1806 gives you "my motives" and you should take a minute to write this into your Code Book as well.

So, take a look at your Line #35 now:


Fig. 1.45

Let's add another bit of code to our Code Book. The number 1024. Unlike 768 that adds, 1024 takes away. As an experiment, type 1024 into Parameter 3.


Fig. 1.46

Look at your Line #35 now:


Fig. 1.47

Let's put the Data box back the way it was with a 768 in Parameter 3. Unless we want to send the Sim scrambling for the nearest bathroom.


Fig. 1.48

OK. Let's make sure our lines are properly linked together. Go back up to Line 11, and in the Data box, make both your True and False lines go to 35. Rewrite your lines. Now Lines 10 through 14 should look like this:


Fig. 1.49

Are we all in sync here? Good!

Time To Test

Have a Sim who is hungry and maybe even a bit uncomfortable AND with low bladder try out the chair to see what happens. I know that's a lot to ask. You may have to run the Sim ragged for a while, maybe jog him around the lot for an hour or so, and then test. Hey! When the proper testing conditions don't exist, we must create them. Right? Right.

ALL GOOD THINGS MUST END

This concludes our Entry Level class, and truly hope this has been an enlightening and enjoyable time for you. Before we move on to this week's final assignment and test, I'd like to leave you with a few parting words, and I sincerely hope you to take them to heart.

With the completion of this class, you will no longer be classified as a "Newbie". You are now classified as a Contributing Member of the hacking community. There will be many opportunities for you to advance and finally become a good hacker. A responsible one.

Stay away whenever possible from the so called super cheat objects. Any time you put one of those out for distribution, the rest of the community looks at you with eyes crossed and that all-knowing look that says: Well, what else can you expect from a newbie? I'm not saying super cheats aren't fun and they should never be employed — I am saying you should use good judgment and use them (if you must) sparingly.

Never claim that an object is 100% your very own, and copyrighted. We covered the details of copyright in our very first lesson. Remember them. You can, however, ask that people please not clone or redistribute your object. That's perfectly legal, but you cannot attack someone for having a like object or even for looking at "your object's" code.

Above all else, please be kind to new hackers or new object creators (I hate the term 'newbie'), and help them out whenever you can. We want to promote sharing and the feeling of closeness amongst ourselves. We want to grow together, not apart, and possibly risk becoming one of those pompous arses that nobody wants to deal with. Believe me, we have a few of those in the community, and nobody likes them. When they ask for help, they tend to get ignored.

I'll now step away from my podium and we can move on to the Assignment. (And aren't you glad!)

Entry Level HAcking - FINAL ASSIGNMENT

Using the skills you've learned during the past 4 weeks, please create a functional object. One that is not a super cheat, and one that does not involve a chair. Create this object with loving care and consideration as if you were building it to put on your site for public distribution.

  1. Using the skills you've learned during the past 4 weeks, please create a functional object. One that is not a super cheat, and one that does not involve a chair. Create this object with loving care and consideration as if you were building it to put on your site for public distribution. When you are done with your object, post it, so we can check it out. I will be available all week long in the Forum and on ICQ should you get stuck.

  2. There will be an online final test on Wednesday. Check our Discussion Forum for the link. The test was designed to evaluate your acquired skills. A final test score of 75% or above means you are capable of moving on to the Intermediate class.

 

Happy Simming, everyone, and I hope to see you in Intermediate!

Graph

Return to Index