Skip to content
Gardenly3D
User Guide
User Guide

Code Editor

Write GardenlyScript automations in the Lua code editor. Full API auto-complete, error highlighting, and --@param annotations to define parameter form controls.

The Code editor is the left pane of the IDE Layout when the Code view toggle is active. It is built on CodeMirror and provides a full-featured editing environment for GardenlyScript (Lua-based) automation code.

Key features:

  • Syntax highlighting — Lua keywords, strings, comments, and numbers are color-coded
  • Line numbers — shown in the left gutter
  • Code folding — collapse/expand function bodies and block structures
  • Auto-complete — press Ctrl+Space to trigger completions for GardenlyScript API methods, Lua built-ins, and variable names in scope
  • Error highlighting — lines with runtime errors show a ruby-red left border; the error message appears in the status bar at the bottom of the editor
  • --@param annotation syntax — declare parameter inputs that appear as form controls in the Parameters panel
1

Write basic automation code

All automations follow a standard structure:

```lua --@name My Automation --@description A short description of what this does

function main() -- Your automation code here end ```

The --@name and --@description annotations set the automation's display name and description in the My Automations tab. The main() function is the entry point — execution starts here when you click Run.

All GardenlyScript API methods are available inside main(). Press Ctrl+Space to see completions. The API is organized into namespaces:

  • garden.entities — query and create entities
  • garden.selection — control canvas selection
  • garden.layers — manage layers
  • garden.measurement — compute geometric measurements
  • garden.ui — show messages and dialogs
  • math, string, table — standard Lua libraries
TIP

Use the Help tab in the Automation panel's How do I… prompt to find the right API methods for your task before writing code. The completions in the code editor are comprehensive but the Help tab provides natural-language descriptions.

2

Use --@param to define parameters

The --@param annotation syntax declares input parameters that appear as form controls in the Parameters section of the Editor sidebar and IDE right pane.

Annotation format: ``lua --@param name type label [default] [options] ``

Examples: ``lua --@param spacing number "Plant spacing (m)" 1.0 min=0.3 max=5.0 --@param plantName string "Plant species" "Rosa canina" --@param layer dropdown "Target layer" "Planting" options=layers --@param includeLabels boolean "Add name labels" true ``

Supported types: number, string, boolean, dropdown, color.

For dropdown type, options=layers populates the dropdown with current project layer names. Custom static options use options="Option A,Option B,Option C".

Declared parameters are available in main() as local variables with the same name as the annotation's first word.

TIP

Always add a --@param annotation for any value that might reasonably change between runs of the automation. This makes the automation reusable across different projects and contexts without editing the code.

3

Read error highlighting

When an automation run produces a runtime error, the code editor highlights the error location:

  • The line that caused the error shows a ruby-red left border in the gutter
  • The status bar at the bottom of the editor shows the error message and line number (e.g. Line 12: attempt to index a nil value (local 'entity'))
  • The Output tab in the right pane shows the full stack trace

Common error patterns:

  • attempt to index a nil value — a variable expected to hold an entity or object is nil; check that garden.entities.findByName() returned a result before accessing its properties
  • attempt to perform arithmetic on a string — a parameter value that should be a number is being passed as a string; check the --@param type annotation
  • undefined global — a function or variable name is misspelled; check for typos

Fix the highlighted line and click Run again to retest.

TIP

Add print() statements before the likely error line to log intermediate values to the Output console. This narrows down which value is nil or of the wrong type.

4

Use auto-complete for API discovery

Press Ctrl+Space anywhere in the code editor to open the auto-complete suggestions panel.

The suggestions are context-aware:

  • After typing garden., the panel shows all top-level API namespaces
  • After typing garden.entities., the panel shows all entity methods
  • After opening a method call, the panel shows the method signature and parameter types

Each suggestion shows:

  • Method name (bold)
  • Parameter list with types
  • A one-line description

Press Enter or Tab to accept a suggestion. Press Escape to dismiss.

Auto-complete also suggests Lua built-ins (string.format, table.insert, math.floor, etc.) and any local variables declared earlier in the same function scope.

TIP

Declare any value that might change between runs — spacing, layer names, plant species, counts — as a --@param. This makes the automation reusable without touching the code, and lets collaborators adjust it via the form without needing to understand Lua.

5

Find API methods while coding

Switch to the How do I… tab in the Automation panel to browse the full GardenlyScript API reference without leaving the editor.

The API reference tab shows all namespaces and methods with signatures, parameter descriptions, and code examples. Click Insert into script on any example to paste it at your cursor position in the Code editor.

TIP

Add garden.output.print() statements just before the suspected error line to log intermediate values to the Output console. This is the fastest way to discover which variable is nil or an unexpected type.

6

Run and Preview from the editor

Press Ctrl+Enter while the editor is focused to run the automation immediately — this is identical to clicking the Run button in the toolbar. The source is saved automatically before each run; there is no separate Save button. To test changes non-destructively, press Ctrl+Shift+Enter to start a Preview run: mutations are applied to the canvas but not persisted to the project until you click Apply. Click Cancel to revert the preview and restore the canvas to its state before the test.

INFO

The Code editor and the Visual Flow graph stay in sync. Edits you make in Code are reflected when you switch to the Visual tab, and vice versa. If a complex edit breaks the graph representation, a banner appears in Visual mode — switch back to Code to resolve it.

TIP

Dragging a number or length parameter slider in the Parameters popover triggers a live canvas preview — the design updates in real time as you drag, before you click Run. This is ideal for dialing in spacing, radius, or count values interactively.

Keyboard Shortcuts

KeyAction
Ctrl+SpaceTrigger GardenlyScript API auto-complete
Ctrl+EnterRun the automation
Ctrl+Shift+EnterPreview the automation (non-destructive trial run)
Ctrl+KOpen API reference for symbol under cursor

Frequently Asked Questions

Where is the full GardenlyScript API reference?

Open it from the Help tab in the Automation panel, or from the Open API docs button in the Visual Flow toolbar. You can also press Ctrl+K while the cursor is on any symbol in the code editor to jump directly to that method's reference entry.

What parameter types can I declare with --@param?

The supported types are number (numeric input with optional min/max), string (text field), boolean (toggle), length (unit-aware distance input that respects metric/imperial), layer (layer picker populated from the current drawing), and choice (dropdown with a fixed list of options). Declare each parameter once at the top of the script; the matching form control appears automatically in the Parameters popover.

Is there a Save button or shortcut?

There is no explicit Save button. The source is saved automatically every time you click Run or press Ctrl+Enter. Changes are also persisted when you close or collapse the automation panel. If you edit the code and want to save without running, close the panel — the draft is retained.

Can I paste code copied from an external editor?

Yes. Ctrl+V pastes code and preserves indentation. If the pasted code cannot be parsed into a node graph, a banner appears in the Visual tab — the code itself still works and can be run normally from the Code tab.

What is the difference between Run and Preview?

Run (Ctrl+Enter) executes the automation and immediately commits all changes to your project. Preview (Ctrl+Shift+Enter) applies the same mutations locally on the canvas but holds them in a temporary state — nothing is persisted until you click Apply. Click Cancel at any point to revert every change the preview made, leaving the project exactly as it was before.