Storage Layers at a Glance
Both are accessed from any script in the level without importing anything.
Level-Local Data: localData
Level.localData and every entity’s localData (Block, Side, Item, Enemy, Ball, Decoration) are instances that behave like a Lua table. You read and write values using standard Lua bracket notation.
localData works like a table but does not support pairs() iteration. You can read/write individual keys, but you cannot loop over all keys.Reading and Writing
- Writing values
- Reading values
Deleting Keys
Set a key tonil to remove it:
Cross-Script Sharing
BecauseLevel.localData is shared across all scripts in the level, any script can read what another script wrote:
1
Script A writes a value
2
Script B reads the value
Saving and Restoring State
localData values are preserved across save/load within the same level session. If the player saves mid-level and loads later, all localData values remain intact.
Campaign-Global Data: campaignGlobalData
Level.campaignGlobalData persists for the lifetime of the entire campaign. Any value you write here in level 1 is still readable in level 5. Use it to track campaign-wide progress, unlock states, or accumulated scores.
Level.campaignGlobalData is only meaningful when the level is played inside a campaign. If the level runs standalone, the data still works but will not persist between separate play sessions.Reading and Writing with Typed Methods
campaignGlobalData uses explicit typed methods — not table indexing.
- Writing values
- Reading values