Skip to main content

Passthrough code

In the boards system, a visual symbol can be configured to emit a data object for use by your program. Normally, the object's fields are simply the symbol type fields whose "Emit" checkbox has been marked. Passthrough code provides a convenient way to input additional fields without having to define them in the symbol type.

For example, suppose we're making a text adventure game. We might use symbols to represent places in our game world. The s_place class might look like this:

class s_item
var name: string
var description: string
end class

class s_place
var north: s_place
var south: s_place
var east: s_place
var west: s_place

# Items in this place
var items: s_item[]
end class

By modeling s_place as a symbol, we can use the board to arrange our places visually. We can even use buddy fields to ensure that every north exit has a corresponding south exit, and so forth. However, symbol fields are a bit awkward for specifying the s_item list. It would be more convenient to write those values as regular source code.

Allowing passthrough code

We can use passthrough code to solve this problem. First, we need to configure the s_place symbol type to enable this feature:

Passthrough code checkbox
Checkbox: Allow extra fields to be input using passthrough code

Editing the passthrough code

Now that the feature is enabled, when an s_place symbol is selected, the property pane shows a "Code…" button:

"Code…" button
The "Code…" button on the symbol property pane

Clicking "Code…" shows the "Passthrough code" window, where you can input the additional data. For example:

{
items: [
{ name: "tree", description: "A tall tree stands in the courtyard." },
{ name: "bench", description: "You see an iron bench, with a small engraving." },
]
}

"Passthrough code" window
Inputting the custom code

Inspecting the output

The items field from our passthrough code will be merged with the symbol type's fields. To see the result, select your symbol on the board. Then click the "Switch View" (⇆) button to view the emitted code.

Emitted code
Viewing the emitted code

The output shows the merged object containing both the east value (from the buddy field) and the items value (from the passthrough code).