Single frame actions and continuous state

Understanding how single frame actions and continuous state work

What is this?

Any action on the DO side of the brain editor, and any child lines, will only run when the WHEN side is true. The WHEN side can be true for a single frame or constantly.

Examples of single frame WHEN statements

WHEN [started to]
WHEN [interacted]
WHEN [B][pressed]

Examples of continuous state WHEN statements

WHEN [after]
WHEN [boolean]
WHEN [not][boolean]

 When incorrectly used

When you use a single frame WHEN statement you cannot attach any action that has to play over multiple frames, such as music, or a timed display.

Single frame input/multiframe action

This…
WHEN [interacted] DO [display][text:Hello World][screen center]

…will only flash the message up onto the screen for one frame, because interact is a single frame input.

This will also not work…
WHEN [interacted] DO
…WHEN [duration timer][4] DO [display][text:Hello World][screen center]

…because the child line can only run for a single frame.

Multiframe input/single frame action

This creates multiple swords…

WHEN [after][numvar:score][>][100] DO [equip][sword]

…because the WHEN input is a continuous state, so the kode line repeats at 30 frames a second. This error can cause your game to seize up, and you may need to reload Spark.

Any WHEN that is blank will also create a continuous state

WHEN DO [create][sword]

This will also create multiple swords

 

Correct use of single frame and continuous state

Single frame input/Multiframe action

WHEN [interacted] DO [boolvar:show text][=][true]
WHEN [boolvar:showtext]
…WHEN [duration timer][4] DO [display][text:Hello World][screen center]

A boolean creates a continuous state from a single frame input. So you can now run multiframe actions.
You need to remember to turn it off after your action is completed if you want it to run multiple times.

WHEN [interacted] DO [boolvar:show text][=][true]
WHEN [boolvar:showtext]
…WHEN [duration timer][4] DO [display][text:Hello World][screen center]
…WHEN [countdown timer][4]DO [boolvar:showtext][=][false]

Alternatively you could use

…/…WHEN [else] DO [boolvar:showtext][=][false]

You can also switch page to run your kode. The single frame action completed on the previous page and is no longer active, so timed elements will now work. Remember to switch back to the first page if you want the action to be repeatable.

WHEN [interacted] DO [switch page][2]
#page 2
WHEN [duration timer][4] DO [display][text:Hello World][screen center]
WHEN [countdown timer][4] DO [switch page][1]

Multiframe input/Single frame action

WHEN [started to][numvar:score][>][100] DO [equip][sword]

This will equip the sword in the frame where the score reaches 100.

WHEN [once] DO [create][sword]

This will create a sword once in the entire game.

WHEN [page entered] DO [create sword]
This will create a sword every time this page is entered.

Multiframe input/Single frame and Multiframe actions

[started to] is a very powerful tile and can be used with a boolean variable so you can have both multiframe and single frame actions

WHEN [started to][numvar:score][>][100] DO [boolvar:levelup][=][true]
WHEN [boolvar:levelup] DO
…WHEN [duration timer][4] DO [display][text:You levelled up][screen center]
…WHEN [started to] DO [equip][sword]

 

Comments are closed.

Powered by WordPress.com.

Up ↑

%d bloggers like this: