Data storage

Database server-side

Tags: database

Databases allow you to store variables permanently, without being able to be modified by others. Its useful for keeping track of currencies, personal best scores and what items a player owns.

TIP

To delete data storage values you can use delete all as a key

WARNING

  • Make sure to use player.accountName (server-side only) instead of player.username
  • You can only store and access data from players who are active in game
  • set, update, transact every 10 seconds per connection/player
  • load every 5 seconds per connection/player
  • 30 Keys per map, keys length is 20 characters. (Object properties are treated as unique database keys)

Set storage server-side

# Set a player value to a specific value
GAME.STORAGE.set(
    "SwatDoge",                     # str accountName
    {kills: 300, nick: "Swat"},     # obj data
    true,                           # bool private (false: private, true: public) Public databases can be accessed by others
    callback                        # action(obj data, bool success, str accountName) callback function
);
1
2
3
4
5
6
7

Update storage server-side

# Updating ADDS the value you give it to the existing value. Negative values will thus be subtracted.
# Removing 5 kills from SwatDoge's kills
GAME.STORAGE.update(
    "SwatDoge",    # str accountName
    {kills: -5},   # obj data
    true,          # bool private (false: private, true: public) Public databases can be accessed by others
    callback       # action(obj data, bool success, str accountName) callback function
);
1
2
3
4
5
6
7
8

Transact storage server-side

# The same as GAME.STORAGE.update but you can not go below 0. If this does happen, the success parameter on the callback function will be false
GAME.STORAGE.transact(
    "SwatDoge",   # str accountName
    {kills: -5},  # obj data
    true,         # bool private (false: private, true: public) Public databases can be accessed by others
    callback      # action(obj data, bool success, str accountName) callback function
);
1
2
3
4
5
6
7

Loading Data server-side

WARNING

Loading from an empty database will result in an error message "No data" and not call the callback

# Load data you stored on your map
GAME.STORAGE.load(
    "SwatDoge",     # str accountName
    "",             # str name of game with public database. (leave empty)
    callback        # action(obj data, bool success, str accountName) callback function
);
1
2
3
4
5
6
# Load data you stored on another map
GAME.STORAGE.load(
    "SwatDoge",     # str accountName
    "lava_run",     # str name of game with public database. (leave empty)
    callback        # action(obj data, bool success, str accountName) callback function
);
1
2
3
4
5
6

Cookies client-side

Tags: localstorage

Cookies allow you to store variables on a users browser. These variables can be modified by users and should not be relied on for source of truth. Useful for settings.

WARNING

Cookies can only store strings as values

# Save cookie
GAME.COOKIES.save(
    "test",   # str name
    "100"     # str data
);
1
2
3
4
5
# Load cookie
str value = GAME.COOKIES.load(
    "test"   # str name
);
1
2
3
4
# Delete cookie
GAME.COOKIES.remove(
    "test"   # str name
);
1
2
3
4
# Check if cookie exists
GAME.COOKIES.has(
    "test"    # str name
);
1
2
3
4