On Our Best Behaviors
by Adam Larson · 04/02/2007 (5:10 pm) · 12 comments
In case you missed it yesterday because you were busy puzzling over the Constructor announcement, we launched an open beta of TGB 1.5. Read more about that here. One of the many new features in TGB 1.5 is that of behaviors. So far everybody seems to like the concept and potential of this system, but there's probably a lot of confusion as to exactly what they can do and how they can be used. I'll try to clear that up.
The high level description: A behavior is a small, self-contained piece of functionality that can be added to any scene object and configured through the editor. They are modular, so you can add many behaviors to an object and the same behavior to multiple objects. The behavior itself defines how an object reacts to certain events.
The first thing you should do when you install the beta is open the BehaviorPlayground project. You can do this by clicking on the giant 'Open' button, navigating to (TGBInstallDirectory)/games/BehaviorPlayground, and opening the project.t2dproj file. The playground level should open by default, but if it doesn't, go to file->open and select playground.t2d. This level is basically just a bunch of objects with various behaviors added to them. Hit the play button to see it in action.

I want to emphasize an important point here. There is no custom scripting done outside of the behavior definitions themselves in this level. If you don't actually have TGB, or haven't downloaded the beta yet, then this may not sound all that impressive. The point is, we are taking a big step here towards having full game building done entirely inside of the editor. Picture with me a library of hundreds of behaviors (created by us at GarageGames and TGB users). These behaviors are all on a site somewhere, complete with a description of what each one does. Then, users can (This hasn't been fully fleshed out or implemented yet). Prototyping will be a breeze and artists and game dev novices can learn the basics without having to learn to code.
Now, of course, I'm sure there are people out there who like the power of scripting, or even coding directly in c++. Rest assured, the behaviors are merely an addition to everything that exists, not a replacement. But, I will say to those people, just because behaviors are ridiculously easy to use does not mean they don't have a lot of power. If I were to start making a game right now, the majority of the game logic would be done through behaviors. There are definitely things that are easier to do outside of behaviors, but for the most part, this is the way future TGB games are going to be made.
A story: The first demo we did with behaviors was last November. We had something pretty similar in appearance to the behavior playground that shipped with the beta. Me and Mark F were giving a demo that, to be honest, was mostly just us playing around (playing with the behaviors is pretty much a game in itself). So I had added an 'AsteroidsControl' behavior to an object (adds keybindings and the functionality for controlling an object like the ship in asteroids). To that same object, Mark added an 'AvoidMouse' behavior. The result was me trying to fly the ship to an arbitrary goal while Mark repelled it with the mouse. This was most definitely not something we intended to do, but it turned out to be pretty fun. And I got to thinking, how would I have actually coded that? I can guarantee my code would have been much more complicated than what was in the behavior definitions.
What I really want to see now is tons of community created behaviors on TDN. There's also potential for behavior packs that contain a set of behaviors for creating a certain type of game. In any case, that can't really happen until people know how to write them. A good place to start is by looking at the examples in the BehaviorPlayground project. Even better, I'll be writing a doc on TDN in the near future (tonight or tomorrow).
Hope everyone's enjoying the beta so far. Feel free to give feedback in the beta forums.
-Adam
The high level description: A behavior is a small, self-contained piece of functionality that can be added to any scene object and configured through the editor. They are modular, so you can add many behaviors to an object and the same behavior to multiple objects. The behavior itself defines how an object reacts to certain events.
The first thing you should do when you install the beta is open the BehaviorPlayground project. You can do this by clicking on the giant 'Open' button, navigating to (TGBInstallDirectory)/games/BehaviorPlayground, and opening the project.t2dproj file. The playground level should open by default, but if it doesn't, go to file->open and select playground.t2d. This level is basically just a bunch of objects with various behaviors added to them. Hit the play button to see it in action.

I want to emphasize an important point here. There is no custom scripting done outside of the behavior definitions themselves in this level. If you don't actually have TGB, or haven't downloaded the beta yet, then this may not sound all that impressive. The point is, we are taking a big step here towards having full game building done entirely inside of the editor. Picture with me a library of hundreds of behaviors (created by us at GarageGames and TGB users). These behaviors are all on a site somewhere, complete with a description of what each one does. Then, users can
Now, of course, I'm sure there are people out there who like the power of scripting, or even coding directly in c++. Rest assured, the behaviors are merely an addition to everything that exists, not a replacement. But, I will say to those people, just because behaviors are ridiculously easy to use does not mean they don't have a lot of power. If I were to start making a game right now, the majority of the game logic would be done through behaviors. There are definitely things that are easier to do outside of behaviors, but for the most part, this is the way future TGB games are going to be made.
A story: The first demo we did with behaviors was last November. We had something pretty similar in appearance to the behavior playground that shipped with the beta. Me and Mark F were giving a demo that, to be honest, was mostly just us playing around (playing with the behaviors is pretty much a game in itself). So I had added an 'AsteroidsControl' behavior to an object (adds keybindings and the functionality for controlling an object like the ship in asteroids). To that same object, Mark added an 'AvoidMouse' behavior. The result was me trying to fly the ship to an arbitrary goal while Mark repelled it with the mouse. This was most definitely not something we intended to do, but it turned out to be pretty fun. And I got to thinking, how would I have actually coded that? I can guarantee my code would have been much more complicated than what was in the behavior definitions.
What I really want to see now is tons of community created behaviors on TDN. There's also potential for behavior packs that contain a set of behaviors for creating a certain type of game. In any case, that can't really happen until people know how to write them. A good place to start is by looking at the examples in the BehaviorPlayground project. Even better, I'll be writing a doc on TDN in the near future (tonight or tomorrow).
Hope everyone's enjoying the beta so far. Feel free to give feedback in the beta forums.
-Adam
About the author
Recent Blogs
• Distance Fading• Particle Alignment
• Meet the T2D Level Builder
• Plan for Adam Larson
• Plan for Adam Larson
#2
04/02/2007 (6:19 pm)
If this is as described, it could really simplify my work on Pharaoh's Frenzy. I've yet to download it, but I may pull it down and play with it later tonight. Being only an intermediate scriptor - and still learning! - anything that I can do in the editor makes my life a LOT easier until I have all the knowledge I need to go down to the bare bones. Thanks!
#3
a 'Grab' behavior, which actives a Follow Mouse code snippet when the object is Clicked ... and drops the object when it's clicked again ...
adding a very little amount of code around this ... you could recreate Solitaire in a fairly short period of time, where as with the current 1.1.3 build, you'd have to write a bunch of onMouseDown, onMouseDrag (or schedule based, I like schedules personally) .. then spend time testing this code, etc, etc ... now, you can skip the tedious 'reinventing the wheel' process and jump right to the core logic ...
I'm viewing behaviors as a way to create code libraries, of reusable, easy to write, simply to apply snippets and functionalities you can assign to objects ...
Now ... can we add/remove behaviors to objects on-the-fly through script easily ... or is there a convoluted series of whacky script calls we have to make to assign behaviors "on the fly" ... like for example, to recreate solitaire, we may want to assign different behaviors to cards based on a logic check ... if it's the Ace, assign the "Jump to Position" behavior ... otherwise, assign the "Drag and Drop" behavior ...
Can we also cancel a behaviors action ... for example, in a "Drag and Drop" behavior where you click to grab, follow mouse and click to release ... can we cancel the release of the object through a logic check ... or re-initiate the 'grab' after a release has been made based on a logic check -- ie; behaviors allow us to tie into 'events' (as it was put), but do behaviors themselves have 'events' (or call backs)
And, I can't wait to start getting into coding behaviors and flooding TDN with tons of cool things ....
04/02/2007 (8:15 pm)
From what I've seen of the behavior system so far ... you could in theory, create a card game ... similar to the Solitaire game that ships with Windows ... by assigning behaviors to card sprites ... a 'Grab' behavior, which actives a Follow Mouse code snippet when the object is Clicked ... and drops the object when it's clicked again ...
adding a very little amount of code around this ... you could recreate Solitaire in a fairly short period of time, where as with the current 1.1.3 build, you'd have to write a bunch of onMouseDown, onMouseDrag (or schedule based, I like schedules personally) .. then spend time testing this code, etc, etc ... now, you can skip the tedious 'reinventing the wheel' process and jump right to the core logic ...
I'm viewing behaviors as a way to create code libraries, of reusable, easy to write, simply to apply snippets and functionalities you can assign to objects ...
Now ... can we add/remove behaviors to objects on-the-fly through script easily ... or is there a convoluted series of whacky script calls we have to make to assign behaviors "on the fly" ... like for example, to recreate solitaire, we may want to assign different behaviors to cards based on a logic check ... if it's the Ace, assign the "Jump to Position" behavior ... otherwise, assign the "Drag and Drop" behavior ...
Can we also cancel a behaviors action ... for example, in a "Drag and Drop" behavior where you click to grab, follow mouse and click to release ... can we cancel the release of the object through a logic check ... or re-initiate the 'grab' after a release has been made based on a logic check -- ie; behaviors allow us to tie into 'events' (as it was put), but do behaviors themselves have 'events' (or call backs)
And, I can't wait to start getting into coding behaviors and flooding TDN with tons of cool things ....
#4
I would guess that a lot of people will jump on the bandwagon of creating bahavior packs.
This is definitely worth spending the time to learn.
04/02/2007 (8:27 pm)
Stephen Zepp showed us in the TGB course the behaviors stuff... It's awesome. He had us in awe by creating the asteroids game in 3 mins (without the additional blah blah blah explaining how it is to work). The classmates and I, we barely got the *bleeping* ship to move around by the end of class time. heheh.I would guess that a lot of people will jump on the bandwagon of creating bahavior packs.
This is definitely worth spending the time to learn.
#5
Awesome to see them so close to release, Adam!
04/03/2007 (8:21 am)
They've come so far *tears up*Awesome to see them so close to release, Adam!
#6
%object.addBehavior(BehaviorName.createInstance()); will add BehaviorName behavior to your %object.
Cheers,
-Justin
04/03/2007 (10:25 am)
@ David,%object.addBehavior(BehaviorName.createInstance()); will add BehaviorName behavior to your %object.
Cheers,
-Justin
#7
04/03/2007 (12:44 pm)
This stuff kicks ass! I used behaviors in Director and now I have them in my fav game engine! Thanks to everyone involved! You guys rock!
#8
04/03/2007 (12:56 pm)
@Tom: glad you are happy to have them... though Director shares an object of the same name and very similar functionality the name was created with the basic word in mind... a "behavior" for gameplay elements, it definitely wasn't conceptualized with Director in mind :)
#9
The first thing that came to mind was how easy TGB would be to pick up for the Gamemaker audience.
Congrats GG, you keep throwing surprises in my sad, boring life :)
04/03/2007 (2:22 pm)
Played with them the day the beta came out, loved them. (Behaviors)The first thing that came to mind was how easy TGB would be to pick up for the Gamemaker audience.
Congrats GG, you keep throwing surprises in my sad, boring life :)
#10
04/03/2007 (3:08 pm)
Interesting. I think there's a lot of potential here.
#11
04/03/2007 (5:06 pm)
So I take a month or two off from coding and now we have this newfangled behavior system. I had a similar idea a while back, but I did it a bit differently. In my project I can assign a Lua script to a TGB object, which will create a Lua table with callbacks to handle game logic. So I can give 20 aliens the same script and it works fine. There's more to it than that but in a nutshell that's what I do now, and all from within the editor (besides the script editing). It's sweet that we have this implemented. Now I can execute Lua code from behaviors too. This is just awesome. It's going to be huge.
#12
04/04/2007 (3:38 pm)
I've been thinking about adding something like this to my own "game engine" for years. I think this is a huge step in the right direction for TGB!! Congrats GG!
Torque Owner Leroy Frederick
Definitely the future of TGB (and general) game making, especially if it allows you to do things that have already been coded in the past with ease by allowing you to just plug em' in, thus allowing for more concentration on gameplay and vision, and less on re-inventing the wheel ;0)
EDIT: Opps, I almost forgot guys and gals, thanks for the great work, TGB (and other good gg products) just keeps getting better and better with every upgrade! It's most appreciated! :0)