Scripting help
Block scripts
Give terrain blocks a script in a Platformer, so they react to the hero: bricks that break, coin blocks, crumbling platforms and seesaws.
In a Platformer, terrain blocks can have a script too. A block script reacts to the hero: a brick that breaks when the hero jumps into it, a block that gives a coin, a platform that crumbles under the hero's feet, or a seesaw that tips as the hero walks along it.
Blocks only react. Their rules start with something that happens to them, like when the {Hero} steps on me. They have no every 3 seconds and no when @coins is 10, so a level full of blocks with scripts stays fast.
Giving blocks a script
A script can go on a few blocks of their own, on a group of blocks with an ID, or on a brush of your own that paints groups.
Opening a block's script
Pick the Script brush in the builder's Behavior drawer and click a block. The Terrain script window opens on that block. Right-clicking a block and picking Open script does the same.
You can also pick some blocks on the map and press Open script in their Script card. The script you write goes on all of the blocks you picked.
One-off scripts
Blocks with a script and no ID run a one-off script. Only those blocks run it. While you build, they have a dashed outline and a scroll on their first block.
Groups
Pick some blocks and type an ID in their Script card, like Brick. They become a group: one ID, one script, and one family. The blocks don't have to touch.
While you build, a group has a dashed outline in its own colour, and a scroll on its first block once it has a script. A group with only an ID has its outline and no scroll.
Your own brushes
A group with an ID and a script becomes a brush of your own. It is a sub-brush of the brush its first block was painted with, named after its ID. Pick that brush (Platform, for example) and it shows in the brush's row, after the plain one ("Which platform?"). It paints the art of the group's first block. An ID on its own never makes a brush.
| What you do | What happens |
|---|---|
| Click | Paints one block. |
| Drag | Paints many. One connected piece is one group. |
| Paint touching one of the brush's groups | That group grows. |
| Paint touching two of them | They become one group, keeping the older one's ID. |
| Hold Shift as you start | The blocks join the group you painted last, even far away from it. |
| Paint anywhere else | A new group, like Brick 2, with the same script. |
Write the script once. Changing it on any of the brush's groups changes all of them. Emptying it takes the brush away, and its groups keep their IDs.
What blocks react to
| Write | When it happens |
|---|---|
when I start | When the level starts. |
when the {Hero} steps on me | When the hero lands on one of my blocks, and again each time they walk onto another one of them. |
when the {Hero} steps off me | When the hero isn't standing on any of my blocks any more. |
when I get hit from below | When the hero jumps up and bumps their head on one of my blocks. |
when I get hit | When the hero's attack reaches one of my blocks. Each swing hits a block once. |
when "alarm" | When any script sends that trigger. See Triggers. |
In these rules, {trigger id} is the block it happened at: the block the hero stepped on, bumped or hit. The {Hero} is the hero who did it.
What blocks can do
| Write | What it does |
|---|---|
hide me, bring me back | Takes all my blocks out of play, so they can't be seen or stood on, then puts them back. |
hide {trigger id} | Takes one block out of play. |
I am not solid, I am solid | Everyone goes through me, though I can still be seen. I am solid blocks them again. |
my pass through is on | The same as I am not solid. off makes me solid again. thru works too. |
flash for 1 second | Blinks on and off, then carries on. |
my hue is 90, my opacity is 50 | Changes how all my blocks look. my size and my angle work too. |
{trigger id} hue is 90 | Changes how one block looks. Leave out the my, and put which block first. |
move down 3 blocks | Moves all my blocks, and whoever stands on them. Up, down, left and right all work. |
my speed is 4 blocks a second | How fast my moves go, when they don't say how long to take. |
my angle is 15 over 0.3 seconds | Tilts all my blocks as one piece. The hero walks along the slope. |
{Game} give 1 coin to the {Hero} | The game gives the hero coins. |
A block you drew yourself in the Addon Lab can show its own poses, like my pose is "Broken".
Blocks that act as one
A group acts as one: a unit. Blocks with no group act as one too when they touch and are painted with the same family. In a unit's script, my is the whole unit. That's how a row of platform blocks crumbles together, or a plank of blocks tips like a seesaw.
Putting blocks in a family
A block family is one script that many blocks share, like every brick that breaks when it's hit. To write one, open Game settings and press Block families in the Scripts card.
To put blocks in a family, open a block's Terrain script with the Script brush. The Family list at the top shows the family of that block's group or unit. Pick a family, and the whole group goes in it, along with every group painted with the same brush. Pick New family… to make one, or No family to take it out.
Edit family shows the family's script in the same window. Press Back to Brick script (or whatever the blocks are called) to go back.
You can also pick blocks on the map and choose a family in their Script card. While you build, a group or unit with a script or a family has a scroll on its first block.
| Write | What it means |
|---|---|
{Blocks} | Every block of my unit, like a family: all {Blocks} hue is 25. |
repeat all {Blocks} … end | Goes through my blocks one at a time, with {this one} each time. |
{First Block}, {Middle Block}, {Last Block} | Blocks of my unit, top row first, left to right. |
if {trigger id} is in {Coin brick} | Checks which family a block is in. |
my angle is 20 tilts the whole unit as one piece. all {Blocks} angle is 20 turns each block on its own spot instead.
Group scripts and family scripts
A block runs its group's script and its family's script. When both have a rule for the same thing, like two when I get hit from below, the group's rule is used. Put trigger my family in the group's rule to run the family's steps too.
The easiest way is to leave those rules to the families. Give the Brick group no when I get hit from below, and make a "Breakable" family and a "Coin brick" family that each say what their bricks do.
Reaching blocks from other scripts
Pick some blocks and give them an ID in their Script card, like Gate, to make a group. Game and level scripts can then write hide the {Gate} and bring back the {Gate}. all {Crumbly} flash reaches every block in a family.
Examples
A family of breakable bricks. The brick the hero hits blinks and breaks, and the rest stay. A brick you drew yourself could show its own "Broken" pose instead of blinking.
A crumbly platform. When the hero steps on it, it flashes, then falls out of the level.
A seesaw. It tips toward whichever block the hero is on, and levels out when they step off.
Good to know
When the hero loses a life or tries again, every block goes back to how it was painted. To keep a change, save it in an @variable and put it back in when I start.
When the same rule happens at two blocks, it runs at both. When it happens again at a block that's still running it, it starts again there.

