Data storage
server-side
DatabaseTags: 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)
server-side
Set storage# 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
2
3
4
5
6
7
server-side
Update storage# 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
2
3
4
5
6
7
8
server-side
Transact storage# 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
2
3
4
5
6
7
server-side
Loading DataWARNING
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
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
2
3
4
5
6
client-side
CookiesTags: 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
2
3
4
5
# Load cookie
str value = GAME.COOKIES.load(
"test" # str name
);
1
2
3
4
2
3
4
# Delete cookie
GAME.COOKIES.remove(
"test" # str name
);
1
2
3
4
2
3
4
# Check if cookie exists
GAME.COOKIES.has(
"test" # str name
);
1
2
3
4
2
3
4