Elements.tagged table is the single entry point for all tag-based entity access.
Setting Tags in the Level Editor
Open the properties panel for any entity in the editor and fill in its Tag field. Tags are free-form strings — choose names that describe the entity’s role in your level design (for example"exit-door", "spawn-trigger", or "collectible-key").
Multiple entities can share the same tag. When you look up a tag that more than one entity uses,
Elements.tagged gives you a table of all matching entities instead of a single value.The Elements.tagged Table
Elements.tagged is a read-only table indexed by tag strings. Each value is either:
- A single entity — when only one entity in the level has that tag.
- A table of entities — when multiple entities share that tag.
Getting a Single Entity by Tag
When you know exactly one entity carries a tag, indexElements.tagged directly:
block:enable() or enemy:kill()), cast it first using one of the as*() methods available on every entity.
Cast Methods
Working with Multiple Entities Sharing a Tag
When several entities share a tag,Elements.tagged["my-tag"] returns a table. Iterate it with a numeric for loop:
Entity Types
The following entity types can all be found viaElements.tagged:
Practical Examples
Get a block and toggle it
Read a ball’s position on level start
Iterate all enemies with a shared tag
Collect all items tagged “bonus-coin”
Checking Whether a Tag Exists
Elements.tagged returns nil for tags that no entity in the level uses. Always guard lookups when the tag might not be present: