Hello, recently I've been hearing about and seeing active objects that apparently have code in them? I was wondering how to do this and if there's any benefits. Sorry if I didn't explain this well enough.






Hello, recently I've been hearing about and seeing active objects that apparently have code in them? I was wondering how to do this and if there's any benefits. Sorry if I didn't explain this well enough.


What you see are called "Behaviors". They are a way you can organize your code, useful if you want to copy/paste objects into different frames with code attached to them.
If you right click on an object in the level editor, and select properties, the second from the right tab is called "Events", it has a mini picture of the event editor, inbetween the A-Z (values) and Quote bubble (about) tabs. In this tab, the bottom area is your list of behaviors for that object. You can click the new button to add a new set of code, and click to edit it will bring you to an event editor just for the behavior code. When in this event editor, you can import objects from the frame so they will be selectable in the event editor.
You asked the right question for sure though, in "If theres any benefits". In reality, behaviors don't add any extra functionality to your project at all. Effectively, the code in your behaviors is just copy/pasted into the event editor at runtime, added below all the regular code in the frame. There isn't any extra tools or abilities you can do in behaviors that you couldn't do in the normal event editor. Instead, the advantage of behaviors is a way to organize your code to make it less cluttered, easier to read and easier to port between frames and such. It might make keeping track of the code related to each object be less of a headache, or let a widget be copy/pasted from an example file into a project with code ready to use. The disadvantage is that you don't have as much control over what order your code is executed, you can't put behaviors above or below normal code.
Behaviors are kind of tricky to find in the help files, search the help index for "Event Properties" and its described there;
Note that behavior code isn't run on a per-object basis as it might give the impression. If you have 10 copies of an object with an event saying "Upon pressing space bar, add 1 to counter", it would just be the same as having a single copy of that line in the event editor, it will only execute once, not ten times.Behaviors.
Behaviors are a list of events, specific to the object. Using the Edit button in this property, you can open a new event editor to edit this list of events. Your object will be the only one listed. You can import new objects with the "Import object" button. You define your events as usual.
The great advantages of the behaviors is that the events are integrated in the object's properties : it means that if you copy the object, the behaviors will be copied at the same time.
Example : you create a button that makes a click. Create a behavior that plays the sound "click" when you press the button. Then if you copy this object to another frame, it will click automatically when pressed.