Skip to main content

Dealing With Fields

In most of the cases, you will want blocks that can accept fields (example: the "say" block).

To implement a field in a block, you can pass a fields key:

Rarry.registerExtension({
id: "myInputExtension",

category: {
name: "My Input Extension",
},

blocks: [
{
type: Rarry.BlockType.STATEMENT, // allows for connection on the top and bottom
id: "sayHiWithValue",
fields: {
abc: {
kind: Rarry.InputType.VALUE, // allows an output block to be connected
type: "String",
default: "default",
},
},
text: "say 'hi' with [abc]",
},
],

code: {
sayHiWithValue: (inputs) => {
const value = inputs.abc; // here, we are getting the value of the input
console.log("hi", value); // example functionality
},
},
});

In the text, every [name] placeholder is replaced by the field with that name from fields. If a placeholder has no matching field, it is shown as literal text.

Example Result

A block with text saying "say 'hi' with [abc]"

When run, the console should show:

hi default

Block Definition Reference

Here's a full list of available properties you can use when defining a block inside the extension's blocks array:

PropertyTypeDescriptionExample
idstringUnique identifier for the block (must be unique within the extension)."sayHiWithValue"
type"statement" | "cap" | "output"Determines the block's connection type: statement (top/bottom), cap (top only), or output (returns a value)."statement"
textstringThe visual label of the block. Use [name] to mark fields/inputs."say 'hi' with [abc]"
fieldsobjectDefines inputs, menus, or statements that appear in the block.{ abc: { kind: "value", type: "String" } }
tooltipstringTooltip text shown when hovering over the block."Makes the character say something."
colorstringCustom block color (defaults to the category color)."#FFAA00"
statementTypestringOptional custom connection check type for statements."action"
outputTypestringOutput connection check for output blocks. Also used to match a custom shape name."Number"
outputShapenumberOptional built-in shape override for output blocks (see table below).1
promisebooleanIf true, the block waits for the value returned by the extension function to resolve.true
duplicateOnDragbooleanIf true, dragging the block out of a stack clones it instead of moving it.true
inlineInputsbooleanWhether inputs are laid out inline. Defaults to true.false
fields.<name>.kind"value" | "statement" | "menu"Defines the type of field."value"
fields.<name>.typestring | string[]Connection check for "value" fields (e.g. "String", "Number", "Boolean", or a custom shape name)."String"
fields.<name>.defaultnumber | string | booleanDefault value shown in the block's shadow input, or the initially selected menu item. Shadow defaults only work for Number, String and Boolean."default"
fields.<name>.itemsArrayMenu items for dropdown menus. Can be strings or {text, value} objects.["left", "right"]
fields.<name>.acceptsstring | string[](For statement fields) defines which statement types can connect."event"
note

statementType and accepts are used exactly as written (they are not automatically namespaced). To avoid clashes with other extensions, prefix custom types with your extension id, e.g. "myInputExtension_action".

Available Output Shapes

You can control how an output block looks using the outputShape property.
These are the supported values:

ValueShapeDescription
1HexagonalUsed for Booleans (true/false)
2RoundDefault shape, used for Numbers, Strings, etc.
3SquareUsed for custom data types
4PillowUsed for Objects
5BowlUsed for Arrays (lists)
6SpikeyUsed for Sets

Each of these shapes is purely visual, they don't change how code generation works, but they help distinguish block types or categories visually.

The Rarry.BlockShape constants map to these values: NUMBER and STRING are 2 (round), ARGUMENT is 3 (square), OBJECT is 4 (pillow), ARRAY is 5 (bowl) and SET is 6 (spikey).

tip

To render a custom shape instead of a built-in one, set outputType (or the field's type) to the shape name. See Custom Shapes.