Leveldot

Entities and logic Experimental

Completely optional. Leveldot builds and exports levels without any of this: use your own entities and logic only if your game needs them.

Experimental Logic is still being built. It works, but it grows and changes with each version: windows, names and steps on this page may change. Share what you need on the Leveldot Discord.

Why?

Logic in Leveldot is a way to see and understand what happens in your level, right inside the 3D view: which trigger opens which door, which button lights which room.

What an entity is

An entity is an object that does something in the game: a light, a door, a lift, a trigger, an effect.

Its script says what it can do, in plain Godot:

In the script In Leveldot
@export variable a setting, edited in Entity Details
public function something it does when told
signal something it announces, to start a connection

Make your own entity type

In Godot

New Entity…

a script that extends LeveldotEntity

Update from Godot

In Leveldot

A tile in the Entities drawer

drag

In the level

An entity with its settings

  1. In Godot, open the Leveldot screen → Entities → New Entity…, which writes the type to res://leveldot/entities/. Any script that extends LeveldotEntity works too.
  2. In Leveldot, open the Entity Catalog (Ctrl+Shift+A) and press Update from Godot (the first time: Import from Godot…). Linking a game imports its types for you.
  3. The type is now in the Entities drawer (Shift+A), next to the built-in ones.

The built-in entities are ordinary LeveldotEntity scripts in the addon. Open one and copy it to start your own.

Use entities in a level

Do Key
Open the Entities drawer, drag a type into the view Shift+A
Search every type Ctrl+Shift+A
Edit the selected entity's settings and events Alt+Enter
Write every entity's name above it Alt+Shift+N

Connect entities Experimental

Logic is "when this happens, do this": a trigger turns on a light, a button opens a door.

Do Key
Make the selected entity tell another one to do something K
The level's own logic: level start, timers, signals Ctrl+L
See the connections in the level F4
List every connection in the level Ctrl+Shift+L
See the connections as a graph Alt+G

Write the script

An entity type is a scene in res://leveldot/entities/: a Node3D root with a script that extends LeveldotEntity.

You write Leveldot reads it as
signal powered_up an announcement with no value
signal fuel_changed(litres: float) an announcement that carries one value
func add_fuel(litres: float) -> void a command that takes one value
func shut_down() -> bool a command that may refuse: return false
@export var capacity := 20.0 a setting; @export_range gives it a min and max
## Pours fuel in. above a member the help text Leveldot shows for it
const LEVELDOT_CATEGORY := "Machines" the group it is filed under in the drawer

Example: a generator

A generator that needs fuel before the lights come back on.

## A generator. Fill it up and it powers the room.
extends LeveldotEntity

const LEVELDOT_CATEGORY := "Machines"

## Sent once, when the tank is full.
signal powered_up
## Sent on every refill, with the litres in the tank.
signal fuel_changed(litres: float)

## Litres it needs before it runs.
@export_range(1.0, 100.0) var capacity := 20.0

var _fuel := 0.0

## Pours fuel in.
func add_fuel(litres: float) -> void:
    if _fuel >= capacity:
        return
    _fuel = minf(_fuel + litres, capacity)
    fuel_changed.emit(_fuel)
    if _fuel >= capacity:
        powered_up.emit()

## Stops it and empties the tank. Refused while it is empty.
func shut_down() -> bool:
    if _fuel <= 0.0:
        return false
    _fuel = 0.0
    fuel_changed.emit(_fuel)
    return true

After Update from Godot, the Generator is in the drawer under Machines, with capacity in its settings. Wire it up in the level with K:

Trigger Area

entered

the player walks in with a can

add_fuel, value 5

Generator

powered_up

after four cans

turn_on

Omni Light

The room lights up