View Full Version : Programmer's Guide to BHAVs
Echo
5th Jun 2005, 01:08 PM
Been seeing a lot of questions about recently asking about hacking and changing behaviors. This is a really slippery topic to write tutorials about, because the standard walkthrough style tutorial can only teach how to do one specific hack, and can be very hard to generalize beyond that particular example. So I had a go at writing a guide to BHAV theory, the bits and pieces that make it easier to edit BHAV files intelligently.
I am NOT an expert on BHAVs. Not even close! Absolute amateur compared to many people on this forum. This document just combines a lot of bits and pieces of information I garnered from this and similar forums over the last several months. So a word of warning - there may be mistakes in this document, but I promise I've done my best to discuss only things I was reasonably certain about.
Specific questions are welcome, (that is, "what did you mean by...?" and "could you explain this part in more detail?"). Generic questions are less welcomed ("how do I make an object?" or "where can I get SimPE?",) and are more likely to result in a polite redirection to a more relevant forum. Corrections, suggestions and criticisms are also entirely welcome.
This document is subject to future modification (in case I fouled something up!)
Thanks for listening, hope you all enjoy!
A Programmer's Guide to Behavior Editing
thefuzmixman
5th Jun 2005, 01:25 PM
well i for one will be the first to post and read your guide. Perhaps if i get the theory down, i will have a better understanding of why i do this, or why when i do this, this doesn't work sorta stuff. thanks so much
Carrigon
5th Jun 2005, 01:25 PM
You did a good job on it. It is hard to help people to understand Simantics. What I usually tell everyone is, Simantics is a language. It's a language that is made up of numbers, but it is still a language, and it can be learned if you are persistant.
Echo
7th Jun 2005, 04:43 AM
Thanks for the feedback :) Especially Carrigon - it was your basic tutorials on BHAV editing in SimPE that got me started on the whole behaviour editing business!
WindBlower
8th Jun 2005, 09:23 PM
Dear Echo
I am just now reading your file now. WOW you did a both fantastic and a user friendly manual. I CANT THANK you enough, This made so many things fit into place (in my head).
Thank you
WindBlower
xanathon
13th Jun 2005, 11:04 AM
Thanks a lot, Echo, I was looking forward to something like this a long time! It is somewhat difficult to find a source of information about this that is a basic overview and does not only rely on one specific topic. Great work!
sirams
22nd Jun 2005, 12:10 PM
Really good thing. I used many basic tutorials but still could not get into details: "why this thing has to be modified that way" and "will it still work if i try to change this BHAV code". With Echo's tutorial it is easier to figure out how to get desired results. Thanks.
simsonite
26th Jul 2005, 01:52 AM
Don't know much about programming (or modding yet), but this was very, very useful. Thanks to the bit about opcodes numeration, and where to extract (from objects), was able to edit the bhav's for the whole game. (Was making new package in simpe and importing semiglobals, but those were'nt of the 2000's instance, and so nothing changed despite changing those bhavs.) The t-f thing was fairly evident, but i wasn't completely understanding until reading this guide that those lines are (some of them anyway) calls to other globals. Thanks for this guide, was looking for something to explain it in this way instead of the basic lets change an objects bhav tutorial. I think now I can do just about anything with the bhav's. thankya thank ya thank ya
Echo
26th Jul 2005, 07:50 AM
I'm delighted you found it useful! I'm looking forward to seeing what mods you come up with. ;)
rebecca17
2nd Feb 2006, 02:31 PM
thankyou! i am not smart enough yet to understand all of it. But it helps me a bit.
lgiese
2nd Apr 2006, 03:14 AM
Promblem with downloading the file. Tried to download BhavGuide.zip and I got a pdf file with 14 pages of garble.
Echo
2nd Apr 2006, 04:20 AM
Downloads fine for me... Have you tried downloading it again? Perhaps something went wrong in transmission? If all else fails, I can email it to you as a word document. :)
alchemist
21st Apr 2006, 05:18 PM
Okay, I made it to page 7 by now, and so far it's great - I love that finally I'm getting explanations for the terms which I find all over the forums: what is SimAntics, what is BHAV, what in all heck is a global, what do the numbers mean...
So, thanks a bunch!
One thought:
"There are many resources online that are excellent at explaining these concepts."
Okay....
But: Where? Because at that point, and later on, I have a dim idea at best of what concepts those are. The best I can do is wait for the first unknown expression and then google "tutorial *expression*" and wade through the first dozen of links.
If you have any recommendation, it would be great if you added them, and it would save a lot of time-consuming searching.
It's worth repeating myself on this: getting an understanding of all the terms is great, it means that I don't have to follow walk-throughs blindly but know what I'm doing. Many many thanks!
Echo
22nd Apr 2006, 03:58 AM
You mean basic programming concepts? Just type "introduction to programming" into google and you'll get hundreds of thousands.
If you're looking for a basic concepts that are BHAV specific, then you'd be better reading this:
http://www.modthesims2.com/showthread.php?t=142907
first. It's much more practical and hands on, and assumes no previous programming knowledge.
Or you can keep going with this one, it's a great resource, but like it says in the intro, it's designed for programmers to learn the simantics specifics and does assume programming knowledge. :)
solfal
7th May 2006, 11:22 AM
Thank you so much! I realy have enjoyed seeing my sim dancing in front of the painting! The tutorial was exelent and I was able to understand it without having any programing experience whatsoever.
However when I started try to make the object interactions for the toddler instead I got stucked. When I make the same changes for the object as in the tutorial but for toddlers only the object turn to be unplacable at the lot.
I have tried with different objects, the painting and toddler object. Do you know why this happeneds or can you tell me wich object will be good to start with to make a toddler object. To start with I only want them to crawl to the object and then sit down.
Echo
7th May 2006, 12:25 PM
Are you able to post a copy of the object here (or on the tutorial thread)? Toddler interactions are slightly different to adult interactions, but most of the stuff in the tutorial ought to work just fine for toddlers (assuming you want hula dancing toddlers, of course!). Being unplaceable makes me think it's not related to the interactions, but to some other change. Placeability is determined before any of the interaction code is accessed normally.
solfal
7th May 2006, 05:21 PM
I remade the package for the fifth time to have for posting and suddenly it worked!
I have no I dea why because I thought I made it thesame all times, but apparently not.
One thing I know I didnīt do is rename the behavior function to interaction. Could this cause the problem?
I would like to have some animation but since the paintig donīt have any toddler animation I cant import it from the painting globals, do I have to clone an object that already have toddler animation?
Echo
8th May 2006, 10:59 AM
The name given to a BHAV is just for human reader benefit, it doesn't actually do anything to the system. If you still have the earlier drafts, I'm still happy to take a look and see if I can figure out what you did differently, but it's your call. :)
The animation lists are the same for all objects, so you don't need to clone a different object. (Just about everything I make is based on sculptures or paintings these days.) If your object doesn't have a table for toddler animations, just make one for it. All you need is a text list with the instance number of 0x89. :)
J. M. Pescado
8th May 2006, 11:03 AM
The name given to a BHAV is just for human reader benefit, it doesn't actually do anything to the system.
This is not true. The name of a BHAV *USUALLY* doesn't matter, but BHAVs can be invoked by Run Tree By Name, which DOES use the name. So arbitrarily changing the names of BHAVs on cloned objects can caused them to behave strangely.
Echo
8th May 2006, 12:34 PM
Oh yeah, my error, allow me to rephrase. :)
The name given to an Interaction is just for human reader benefit, it doesn't actually do anything to the system. The same is true for object functions, events, and most other BHAVs, with the exception of those that get run using a "Run Tree By Name" call. These often (although not always,) have names that begin with "CT", to help differentiate them to the reader.
solfal
8th May 2006, 09:05 PM
I did overwrite the bad package, but here is the new one and it workes!
I have tried to make the toddler stop playing when it is tiered, but I couldnīt figure it out. How do I tell the toddler to quit?
Echo
9th May 2006, 12:03 PM
Well done! Congrats on a working object. :)
As far as telling a toddler to quit when it's tired... Let me rephrase your question, as it may make the answer a little more obvious:
If "My motive (Energy) < -60" is true, then finish the interaction. Otherwise, keep going in the loop.
The tutorial should show you how to manage If statements like that, but if you're still stuck PM me and I'll send you the code. :)
As an extra note, if your object is only ever going to be used by toddlers, then it's good practice to specify the toddler list in the "Animate Sim" commands, rather than the adult list. If you look at your Animate Sim commands, you'll see one of the operands is "81". Change that to "89". That box is just saying which text list to look at first. In your case, it'll make the Animate Sim commands actually display the correct description for the animation you're running.
Of course, since toddlers that run the animation will automatically look to that table anyway it's not strictly necessary, it just makes the code a bit clearer. :)
solfal
9th May 2006, 11:23 PM
I made two misstakes, I tried to finished the operation with true and I didnīt use a minus (stupid, I didnīt read the walues the game use properly).
When you rephrased the question it all come clear. You have a great way of explaining things in a simple way.
I couldnt understand why the adult animation commands still showed when I used toddler commands and the toddler commandes worked. Using "89" made it so much easier to work with.
Thank you so much. I am a proud creator of a new toy. Here it is
solfal
26th May 2006, 05:26 PM
Hi!
I have been playing around with the potty animation, I thought I would like to make a little chair for the toddler.
I have two problems. I think I need to tell the toddler to go to a routing slot, but I dont know where to set that value.
It looks like I have to snap the toddler to the object to get the animations to work but I dont know where to set that either.
Perhaps this is way over my head. :lol:
solfal
28th May 2006, 02:01 PM
I have done some reading about routing slots and it seems to be rather complicated. I made it the other way around instead. I cloned a potty and deleted the BHAV that have to do with training and bladder and set it only awalible for toddlers to use. It actuelly worked!
Echo
29th May 2006, 10:47 AM
Well done coming up with that solution. And just as well too, because I actually didn't notice that you'd posted a question! Yes, slots are quite unpleasant to work with, which is why I tend to clone objects that have the right slots and then change everything else around to suit. :)
solfal
30th May 2006, 08:02 PM
Thank you!
Well I almost got it to work :lol: . When I tried the object some more times I noticed that sometimes when I tell the toddler to stop using it, sometimes he crawl down to the floor as he is supposed to, but sometimes he flies away behind the chair. - get an error I guess?
I have gone trough the lines several times but there is a lot of things I dont understand such as all the expression-local variable lines.
Do you think there is an easy sulotion for this?
Solfal
(Guess all my questions should fit better in your tutorial tread, but I did read them both and accidently started to post here)
solfal
31st May 2006, 02:25 PM
Sorry for spamming this tred, but if you pop by I want to tell I think I solved the problem :D . I had one animation return false instead of going to the same place as the true one.
Its still strange that when I tell the toddler to stop only the tantrum sound and not the animation workes, but when the toddler stop itself both workes. They goes to the same places (as far as I understand!)
No big deal though. I can live with that.
Solfal
Echo
3rd Jun 2006, 05:43 AM
Sorry for spamming this tred, but if you pop by I want to tell I think I solved the problem :D
Heh, cool. :) You seem to have a pretty good control of bug fixing!
solfal
4th Jun 2006, 08:46 PM
Thank you! That was a great compliment :D
MP3
10th Jul 2006, 06:39 AM
Well done Echo. This guide helped alot :)
I was able to creat my "Tranquility" by Maxx Hunt from your BHAV tutorials (if you can call them that). Give yourself a cookie ;)
MP3
seresv
30th Sep 2006, 09:50 AM
Ok
This is an adult bed,
i need help with it. So far you can choose which type of act you want. However my sims can only choose one choice when it is on auto . Can you plz tell me how i can fix this . I try instance numbers for the test for auto, but when i choose the auto of the bhav i want to do automatically all the category disappear execpt one . plz help me because i want to post this object really bad. Ok i couldnt find anothe site to ask for help so i posted it here .
Echo
1st Oct 2006, 02:46 AM
Your question has be a bit bemused, but here are some notes:
Very first thing - do not use BHAV numbers higher than 0x1FFF unless you want to override semiglobals! 0x308C is definitely way out. Make sure all your local BHAVs start with a 1. :)
If you want a sim to be able to run something autonomously, then the "Autonomy" field in the Pie Menu functions has to be set to 0x32. If it's set to 0x64 then it can only be run by a user clicking on it.
I noticed that you had an attribute to keep track of whether its supposed to be autonomous or not, but I can't really see how this is meant to be used... In the interaction guards you check whether attribute 6 is 0, and if it is it fails instantly. That means that if you select "Autonomy > off" then you cannot run the interaction at all... Can you tell me what the intended purpose of attribute 6 actually is?
seresv
1st Oct 2006, 03:57 AM
ok i dont know how long i can keep that file posted up, but this is what i did to it so far . I got rid of the sexual choice pop up menu and just only let it have the regular menu to choose from . The instance numbers i put them all back to one ,because like u said they were way out of range . Now the only thing is the autonomous menu for people to turn it on and off. If i remove it there ,im gonna have to go to all my bhavs and elimatinated it. Is there any way i can keep it and make it work with all the choices autonomously.
just4friendssims
14th Oct 2006, 12:16 AM
WOW,i just finished the tutorial
i cant beleive that i can make my own custom interaction
thanks alot
abug
3rd Jun 2007, 02:22 AM
This makes a convenient pocket resource. Good stuff.
EDIT: erm yeah just noticed the previous post was last year...my bad. Though it's still a useful resource in 2007.
vampire_girl_77
10th Dec 2010, 11:06 PM
I think this will help me understand it better, I have read the guide and it is making lot more sense. I wish coding for games had less numbers. It isn't like that in HTML.
Echo
14th Dec 2010, 09:36 AM
Hi vampire_girl! :)
You might find that the "First Custom BHAV" tutorial is of more help to you than this one. It's more up to date, and more accurate. ;) You can check it out here:
http://modthesims.info/showthread.php?t=142907
vBulletin v3.0.14, Copyright ©2000-2013, Jelsoft Enterprises Ltd.