Scripting help

Bosses made of parts

Bosses with a script for each part, their poses, naming a part in a script, and worked examples with the Sunflower's three heads.

Some bosses are made of parts, and each part has its own script. The Sunflower has a body and three heads. The Junkyard crane has tracks, an upper, a string, a claw and a raccoon driver. Its Character script window has one tab for the body and one for every part.

A part is joined to its boss. Its home is the spot where it joins on, so "go home" takes it back there, and it can never go further than its reach. A head can reach 7 blocks. The boss is beaten when every part that can be hit is beaten.

A part's art has poses, and "my pose is" shows one of them until you pick another. "my pose is normal" goes back to how it looks when it moves or stands.

BossPartsPoses
SunflowerBody, left head, middle head, right headwindup, lunge
Horned BubbleBodywindup, impact
Junkyard craneBody, tracks, upper, string, claw, drivernormal
Spider Boss (Adventure)Body, spider 1 to spider 8 (each with its own script)
Bubble Snake (Adventure)Body, bubble 1 and on (named, no scripts of their own)

Naming a boss's parts

A boss's own scripts, and its parts' scripts, name a part with "my" and the part's name in braces. The left head can talk about "my {right head}", the same way your foot could talk about "my head". Each kind of boss has its own part names. The boss's main part is "my {body}", and the whole boss is {boss}.

Other scripts, like a level's, say whose part it is: the part, "of", then the boss's ID. You can put "the" in front of either one if it reads better.

What you wantWrite it like
When one of my boss's parts is beatenwhen my {left head} is beaten
When one of my boss's parts gets hitwhen my {middle head} gets hit
When the boss's body gets hitwhen my {body} gets hit
When the whole boss is beatenwhen {boss} is beaten
From a level script, another boss's partwhen the {Big Flower}'s {right head} is beaten
The same, without the 'swhen the {Big Flower} {right head} is beaten

An ID can't have a comma in it.

The body can call a public function learned by one of its parts. A call waits for that exact part to finish unless it ends with and go.

my {string} reel string with @length is 1, @seconds is 0.4

I am harmless controls whether that exact part hurts the hero. I am invulnerable controls whether the hero can hurt it. They are separate: the crane's claw is harmful and invulnerable, while its exposed driver is harmless and vulnerable.

The crane's upper and string also have physical settings. Their timed changes start immediately, so one custom trigger can turn the upper and pay out the string on the same tick.

my swivel angle is 180 degrees over @seconds seconds with ease-in-out
my length is 2.6 blocks over @seconds seconds with ease-in-out

The Sunflower boss

The Sunflower is a Platformer boss. Its body is a tangle of vines, and it has three heads on long stems. The examples on the rest of this page all use it.

The Sunflower boss: a body of twisted vines with three angry flower heads, one on the left, one in the middle and one on the right.

The hero can't hurt the body. Each head takes 3 hits, and the Sunflower is beaten when all three heads are. A beaten head drops off and its script stops.

PartWhere it isHitsReach
BodyThe vinesNoneNone
Left headLow, on the left37 blocks
Middle headHigh, in the middle37 blocks
Right headLow, on the right37 blocks

A head's poses

A head has three looks. From left to right in the picture they are normal, windup and lunge.

One Sunflower head in three poses: normal with its teeth shut, windup with its mouth opening, and lunge with its mouth wide open.
LineWhat the head shows
my pose is windupIts mouth starts to open: a bite is coming
my pose is lungeIts mouth wide open, for the bite itself
my pose is normalBack to its usual face, swaying on its stem

What the Sunflower does by itself

The Sunflower's body tells the heads when to bite, so they take turns. While it can see the hero, the left head bites, then the middle head, then the right head. Then all three bite together. A beaten head's turn is skipped.

The body sends the trigger "sunflower bite" to one head at a time, and "sunflower big bite" to all three at once. Each head has a function, bite with @reach, @seconds. It winds up, bites toward the hero, and goes back to its stem. A hit sends it home early.

This is the part of a head's script that listens to the body:

when "sunflower bite"
  if trigger @flower is {boss}
    if trigger @head is {me}
      bite with @reach is trigger @reach, @seconds is trigger @seconds
    end
  end

Open the Sunflower's Character script window to read the whole of each script. The Body tab has the turns, and each head's tab has its bite.

Writing your own head script

A script you write on a head's tab takes the place of that head's own one. The head then only does what your script says. When it is that head's turn, the body skips it, unless your script still has the when "sunflower bite" part above.

Working with the three heads

Each example below says which tab it goes on. Open the Sunflower's Character script window and pick that tab first.

A quick, short bite

This goes on the Left head tab. The left head bites more often than the others, with less warning, but it only reaches 3 blocks.

every 1 to 2 seconds
  if I see the {Hero}
    my pose is windup
    wait a quarter of a second
    my pose is lunge
    move toward the {Hero} 3 blocks very quickly
    my pose is normal
    go home quickly
  end

A slow, long bite

This goes on the Middle head tab. The middle head holds its windup for a whole second, so the hero has time to run, then bites as far as a head can reach.

every 4 to 5 seconds
  if I see the {Hero}
    my pose is windup
    wait 1 second
    my pose is lunge
    move toward the {Hero} 7 blocks quickly
    wait a quarter of a second
    my pose is normal
    go home over 1 second
  end

A head that ducks away

This goes on any head's tab, in place of its other "when I get hit" lines. When the head is hit, it pulls back away from the hero, waits, and comes back.

when I get hit
  my pose is normal
  run away 4 blocks very quickly
  wait 2 seconds
  go home over 1 second

One head helps another

This goes on the Middle head tab, under its other lines. When the hero hits the left head, the middle head bites back at once.

when my {left head} gets hit
  my pose is lunge
  move toward the {Hero} 7 blocks very quickly
  wait a quarter of a second
  my pose is normal
  go home quickly

Getting angry when a head is beaten

This is a whole script for the Right head tab. Its bite has no "over" time, so it goes at the head's own speed, and the head speeds up each time one of the other two heads is beaten.

every 3 seconds
  if I see the {Hero}
    my pose is lunge
    move toward the {Hero} 5 blocks
    my pose is normal
    go home
  end

when my {left head} is beaten
  my speed goes up

when my {middle head} is beaten
  my speed goes up

A head that hunts when it is hurt

This is a whole script for the Middle head tab. The head only sways on its stem at first. After two hits it opens its mouth and follows the hero, as far as its stem lets it.

when my health is below 40%
  my pose is lunge
  my speed is fast
  chase the {Hero}

The body speaks for the heads

This goes on the Body tab. A head moves and shows poses, and the body does the talking: it says something each time it loses a head.

when my {left head} is beaten
  say "Ow! My left head!"

when my {right head} is beaten
  say "Not that one too!"

when my {middle head} is beaten
  say "You'll be sorry!"

A level that watches the boss

This goes in the level's script. Give the Sunflower an ID in its Object settings first, like "Big Flower". Then the level can open a door when one head is beaten, and another when the whole boss is.

when the {Big Flower}'s {left head} is beaten
  open the {Side door}

when the {Big Flower} is beaten
  open the {Exit door}

Which lines a head can use

A head is a small part, so it can do less than a whole enemy. This table shows what works on a head's tab.

What you wantWrite it like
Show a posemy pose is windup
Bite toward the heromove toward the {Hero} 5 blocks quickly
Pull away from the herorun away 3 blocks
Move left or rightmove left 2 blocks
Go back to its stemgo home
Follow the herochase the {Hero}
Move faster or slowermy speed is fast
Pausewait 1 second
Do something again and againevery 3 seconds
Only when the hero is in viewif I see the {Hero}
React to its own hitwhen I get hit
React when it is nearly beatenwhen my health is below 40%
React to another headwhen my {right head} gets hit

Talking, sounds and changing the level go on the Body tab or in the level's script.