Storage Layers at a Glance
Both are accessed from any script in the level without importing anything.
Level-Local Data: Level.localData
Level.localData is a RawLocalData instance scoped to the current level. Values written here are available to every script running in the same level session, but they do not carry over to the next level.
Use Level.localData to share state between multiple scripts within one level — for example, a counter that several block scripts all read and write.
Reading and Writing with RawLocalData
RawLocalData provides strongly-typed getter and setter methods. Each method accepts a key string and works with a specific Lua type.
- Writing values
- Reading values
Checking and Deleting Keys
Campaign-Global Data: Level.campaignGlobalData
Level.campaignGlobalData is a LocalData instance that 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.
LocalData exposes the same typed API as RawLocalData — the same setBool, getInteger, setString, and related methods — so everything you learned above applies here too.
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.Structured Data: LocalArray and LocalObject
For more complex payloads you can create LocalArray and LocalObject instances. Both support the same value types: nil, number, string, boolean, nested LocalArray, and nested LocalObject.
LocalArray
A LocalArray is an ordered list you can use like a Lua table with integer keys.
LocalObject
A LocalObject is a key-value map with string keys — similar to a Lua table, but designed to work with the data storage system.
Sharing Data Between Scripts
BecauseLevel.localData is global to the entire level, any script can read what another script wrote. This makes it easy to coordinate state across entity scripts without using signals.
1
Script A writes a value
2
Script B reads the value