Skip to content

Behaviors and scripts

Updated

Behaviors are scripts attached to objects. You write them in JavaScript in a built-in code editor with completion and inline documentation, and the values they expose as slots appear in Properties so you can tune them without editing code.

Use either of these:

  • Add → Logic → Behavior creates a new behavior object in the scene.
  • Select an existing object, choose Add Component in Properties and pick the Behavior component from Scripts.

In the behavior’s section of Properties, the Script field shows a file name such as MyObject.jx. Click it to open the behavior’s source in its own tab in the workspace. Each behavior keeps its own tab until you close it.

If no behavior is selected, the editor shows “Select a Behavior to edit its source.”

The code editor toolbar has:

Button Shortcut What it does
Undo / Redo Ctrl+Z / Ctrl+Y (⌘Z / ⌘⇧Z on macOS) Step through your edits.
Save Ctrl+S Checks the code and, if it compiles, applies it to the behavior.
Auto indent Ctrl+Shift+F Formats the code.
Find Ctrl+F Searches the code.
Smaller / larger text Changes the editor font size.
Compile Checks the code without applying it. On success the Console shows “Behavior compiled successfully.”

For the other shortcuts, use ⌘ instead of Ctrl on macOS.

While you type, the editor offers completion for the scripting API (Ctrl+Space to request it), shows documentation when you hover a name, and shows parameter help after ( and , (Ctrl+Shift+Space). Escape dismisses it.

Edits stay as a draft until you save them. When code has an error, the editor marks the line and the Console shows the message.

The variables a behavior declares as slots appear in its section of Properties once the code compiles. Slot fields match their type: switches for booleans, number fields and sliders, colour pickers, text, drop-down lists, and object pickers (Select object, or None) for references to other objects in the scene. A slot can also be a button. Each slot has Reset to default.

See Slots and Directives for how to declare them, and how labels, groups and read-only fields are set.

Preferences → Code Editor sets the editor’s Font, Font Size, Tab Size, Word Wrap and Format On Save.