Scripting help
The hero script
The hero's own script, for how the hero reacts to the world. Game and level scripts reach it with {Hero}.
The hero script belongs to the hero. It says how the hero reacts to the world: what they say when they get hurt, how they look after a power-up, and what they can and can't do. Every hero runs it, so in a game with friends online, each hero has their own copy.
In the hero script, I and my mean the hero. my health is 50% changes the hero's health, and say "Ouch!" puts words in a bubble over the hero.
Making the hero script
The hero script says how every hero in your game reacts, like what they say when they get hurt. To write it, open Game settings and press Hero script in the Scripts card. It opens in the same script window as the game script.
This hero script makes the hero shout and glow when they're hurt:
when I get hurt
say "Ouch!"
my effect is fire
wait 1 second
my effect is noneWhat the hero hears
These when lines are only for the hero script. Each one happens for this hero.
| When line | When it happens | Works in |
|---|---|---|
when I join | The hero comes into the game. Use it to set the hero up. | Both games |
when I get hurt | Each time the hero is hurt. | Both games |
when I am beaten | The hero runs out of health. | Both games |
when I come back | A beaten hero comes back to play (online, with Respawn). | Both games |
when I collect a coin | Each time the hero picks up coins. | Both games |
when I attack | Each time the hero swings. | Both games |
when I stand still for 5 seconds | The hero has stood still that long. Moving lets it happen again. | Both games |
when I find a shard | The hero finds one of the goal's shards. | Adventure |
when I get a goal key | The hero finds one of the goal's keys. | Adventure |
when I gain a skill | The hero gains a skill, like Dash. | Adventure |
when I jump | Each time the hero jumps. | Platformer |
when I crouch | Each time the hero crouches down. | Platformer |
when I hatch a power-up | The hero hatches a power-up egg. | Platformer |
when I get an extra life | The hero earns an extra life. | Platformer |
when my shield breaks | One of the hero's shields breaks. | Platformer |
What the hero can do
The hero script changes the hero themselves: how they look, what they say, their health and lives, and what they're able to do.
How the hero looks and talks
The hero has the same look words as a character: my opacity is 50, my hue is 90, my look is dark and my effect is frost. say "Hello!" shows words over the hero's head for a few seconds.
The hero can spin, tilt and grow too, with I am spinning, my angle is 45 and my size is 150% (see Spinning, tilting and growing). A bigger hero is easier to hit, but their weapon reaches no further.
Health, lives and holding still
| Step | What it does | Works in |
|---|---|---|
my health is 50% | Sets the hero's health, in percent of full. | Adventure |
my lives is 5 | Sets how many lives the hero has. | Platformer |
I freeze / I unfreeze | Keeps the hero still for a story moment, then lets go. | Both games |
Check them with if my health is under 30% or if my lives is under 2.
The hero script can also read where the hero is, with my row, my column and my distance to the {Door}. The player moves the hero, so my row is … doesn't work here. See Where a character is.
Abilities
| Step | What it does | Works in |
|---|---|---|
my attack is off / my attack is on | Stops the hero swinging, for a peaceful village, then lets them. | Both games |
my jump is off / my jump is on | Stops the hero jumping, then lets them. | Both games |
I gain dash / I lose dash | Gains or loses a skill: dash, smash or swim. | Adventure |
I get a speed boost | A power-up, as its egg gives: speed boost, super jump, jetpack or invincible. | Platformer |
The hero's own @variables
my @karma is 0 at the top of the hero script gives the hero a @variable of their own. Online, each hero has their own value. It lasts through deaths and worlds.
Asking the player on a scroll
The hero script can open a story scroll and ask its own player questions. Online, each player gets their own scroll, and their answers go into their own hero's @variables.
Write the my lines at the top, so @name and @kind are this hero's own. Without them, the answers go into the game's @variables, which the whole team shares.
The game and level scripts can read a hero's answers, like if the {Hero} @kind is "Elf" (see Reaching the hero from other scripts).
Reaching the hero from other scripts
The game script and level scripts reach the hero with {Hero}, as they reach a character by its ID. {Hero} is the hero who set off the rule, like the one who got hurt in when any {Heroes} gets hurt. {Heroes} is every hero.
Enemies and villagers use {Hero} too. In their scripts, it's the hero they meet, so a healer writes the {Hero} health is 100% and checks if the {Hero} health is under 30%.
| Write | What it does |
|---|---|
the {Hero} power up | Runs the hero script's power up function for that hero. |
the {Hero} health is 100% | Tells the hero one of their own steps. |
the {Hero} @karma goes up by 1 | Changes the hero's own @karma. |
if the {Hero} @karma is at least 3 | Reads it. |
if the {Hero} health is under 30% | Checks the hero's health. In a Platformer, the {Hero} lives too. |
if the {Hero}'s row is over 5 | Checks where the hero is. the {Hero}'s distance to the {Door} too. |
all {Heroes} freeze | Tells every hero, wherever they are. |
when any {Heroes} jumps | Happens for each hero who jumps. |
This level script rewards whoever opens the chest:
when any {Heroes} opens the {Treasure chest}
the {Hero} power up
the {Hero} @karma goes up by 1And this is the hero script's power up:
my @karma is 0
learn to power up
my hue is 60
say "Power!"
endWaiting for the hero online
Alone, the {Hero} power up waits for the hero's power up to finish before the next line runs. Online, it doesn't wait: the next line runs straight away, as if you wrote the {Hero} power up and go.
So online, a line after a tell can happen before the hero's function is done. If the order matters, put the next step inside the hero's function instead.

