Skip to content

Branches and transitions

Nothing moves between the three sub-states yet. What moves a machine is a question with a cell for each answer, and those cells are branches.

Click the Every Frame cell of Playing and add Check Mouse Button, with Button left and When Clicked.

Check Mouse Button on Playing’s Every Frame, set to left and Clicked.

Notice where it went: on the parent, Playing, not on Idle. The click has to be heard whatever the sprite is doing, and that is exactly what the last page bought you.

The card now has two cells of its own, True and False. Every question in Hengo comes this way: Is Near has Yes and No, Wait has Finished, and every animated action has one too. That is why you rarely need an If wrapped around a question, the question already branches.

The True and False cells the question adds to the card.

Click the True cell. A small editor opens with four things in it:

PartWhat it does
Target buttonWhere this branch goes. Nowhere means it stays put
Transition nameThe text printed on the arrow in the diagram
+ (circle)Creates a state and points this branch at it, without leaving the editor
+ (list)Adds a step that runs on this branch, staying in this state
The branch editor and its four parts.

The target and the steps are stored apart, so a branch can carry both, but not in one pass: the list + closes this editor to open the action search, and setting the target means clicking the branch cell again afterwards. The other way round, and the one the rest of this path uses, is to end the branch’s steps with a Transition action.

Either way the change of state comes last. It ends the state, so nothing after it would run.

On the True cell’s editor, set the target to Aim and type clicked in the transition name. A transition card appears under the branch and an arrow joins the two frames, labelled with the name you typed. Clicking that card takes the canvas to Aim.

Pointing True at Aim, named clicked, and the arrow it draws.

The name is the field people skip, and it is the one that makes the diagram worth looking at. Playing → Aim says where; Playing → Aim reading clicked says why. In a machine with eight states that is the difference between a diagram and a bowl of spaghetti. Name every transition in the words you would say out loud: clicked, arrived, lost sight, out of ammo.

Compile and play. Nothing visible happens yet, Aim is empty, but open the Debug tab while the game runs and the machine hops over on every click.

The Debug tab showing the machine hop from Idle to Aim on each click.