Variables and binds
A click tells you where the mouse was at that instant. To walk there over the next second you have to keep it somewhere, and that somewhere is a variable.
Make one from the field that needs it
Section titled “Make one from the field that needs it”Open the Aim frame, click its Start cell and add Set Value. Click the
card’s name to open its panel: every field there has a small +, Create and bind a new variable.
Use it on Target, name it target, type Vector2.
One click creates the variable, binds the field to it and lists it in the sidebar. On a field that receives a value the button is shorter still, Create a variable named after this output, and it asks nothing. The other way round, New Variable on the Props tab, is there for when you are planning ahead, but the moment you need a variable is usually the moment you are looking at the field that wants it.
Right-click a variable’s row in Props for its type, its default and Is Export, which puts it in Godot’s own inspector: see Properties.
The five things a field can hold
Section titled “The five things a field can hold”A chip on a card is just the literal case of something with five settings. In the card’s panel, each field has a row of small buttons that switch between them:
| Source | How | When |
|---|---|---|
| Literal | Type it into the chip | A fixed number, a colour, a piece of text |
| Bind | The circle button | Read a variable, a property of the node, or a built-in value |
| Expression | The calculator button | A one-off bit of maths the actions do not cover |
| Inline action | The action button, or the input pin on the card | Feed the field with another action’s result |
| Wire | Drag from an output dot to an input pin | Reuse a value a step above already produced |
A field holds one source at a time: picking a new one drops the old.
The inline action row has a rule of its own: only pure producers are offered, actions that
just compute a value, with no branches and no body. That is why Random Float can go inside a
field and Wait cannot, and a Wait you need the result of goes in the chain, storing into a
variable the field then binds to.
Bind the value
Section titled “Bind the value”Still on the Set Value, set Value with the bind button, then Mouse Position.
The bind list is longer than “your variables”. At the top are built-in values, Self,
Node path…, Mouse Position, Screen Size, Delta, Random Float, Key pressed… and more,
which cost no action at all to read. Under them come your variables, filtered to the types that
fit the field, and then the properties of the node itself, whatever the class you extended
exposes: position and modulate on a Sprite2D, plus velocity on a CharacterBody2D.
Some fields are where a value lands rather than where it comes from, like the Target you just
filled: those take a bind and nothing else, because randf() = 5 is not a thing you can write. They
read not set until you give them one, so an unfinished step is visible instead of silently doing
nothing.
Leave Aim
Section titled “Leave Aim”Click the Aim entry’s Start cell again, or the Add action node after the step, and add
Transition, pointing its To branch at Walk and naming it going there.
Fill Walk
Section titled “Fill Walk”On Walk’s Every Frame cell, two steps:
- Lerp Toward, with Target bound to the node’s
position, To bound to thetargetvariable, and Weight0.1. - Is Near, with A bound to
position, B bound totargetand Distance8. Point its Yes cell atIdleand name the transitionarrived.
Play it
Section titled “Play it”Compile and play. The sprite slides to wherever you click, and you can click again mid-slide to change its mind, because the click check is on the parent and keeps running under all of it.
That is a playable thing, built out of six ideas. The next two pages are about not repeating yourself.