Multiplayer & networking
Networking allows you to send variables to the server, which can then send it back to other players, or store it in a database.
WARNING
Networking must be optimized at all costs
- Data: 2000 bytes per message
- Broadcast (server to all): 10 msg per second
- Send (server to client): 20 msg per second per user
- Send (client to server): 40 msg per second
- Message id string: 10 Characters
server-side client-side
Sending dataFirst off you have to send your variable to either the server or the client, they will be able to listen for the variable so they can use it.
Sending is used for sending data to one specific user.
server-side
Broadcasting dataBroadcasting allows you to send data to all connected clients.
# Send data to all clients
GAME.NETWORK.broadcast(
"test", # str message name
{a: 1} # obj data
);
2
3
4
5
server-side client-side
Receiving dataOnce the message has been sent, we can listen for it and use its given object.
server-side client-side
Detect rate limitingKrunkScript rate limits you to prevent spam over the network.
# Will return a "success" boolean, if false you are being rate limited
if (GAME.NETWORK.broadcast("hi there", {a: 1}) {
# message was sent
}
else {
# message rate limited
}
2
3
4
5
6
7
server-side
Sending & broadcasting chat messagesYou can send chat messages from the server.
WARNING
- Send: 2 msg per second
- Broadcast: 2 msg per second
# Send message to specific player
GAME.CHAT.send(
player.id, # str player id
"hello world", # str message
"#FFF" # str color
);
2
3
4
5
6
# Broadcast message to all players
GAME.CHAT.broadcast(
"hello world", # str message
"#FFF" # str color
);
2
3
4
5
client-side
Movement syncingEvery second the server sends the players position to the client. Once that information arrives at the client, the client retraces its steps since that point in time to now, using the corrected information that it has received from the server.
If your movement code includes custom playervalues, those have to be registered, to be included in the sync.
TIP
Check out this example to add basic double jumping using server syncing
WARNING
- To sync a player property, the property must exist first (currently it gives a wrong error)
- Syncing objects is not yet possible
- Sync values can be up to 16 characters long
- You can have up to 20 sync variables at once per player
# Create player reference
obj players = GAME.players.getSelf();
# Set property
players.hasDoubleJump = true;
# Start syncing player value
player.registerSyncValues(
"hasDoubleJump" #str object key
);
2
3
4
5
6
7
8
9
10
# Stop syncing player value
player.unregisterSyncValues(
"hasDoubleJump" #str object key
);
2
3
4
client-side
Open a window to a different game or platformGAME.URLS.openDiscord(
"YBnq2um" # str discord invite url
);
2
3
GAME.URLS.openOpensea(
"https://opensea.io/SwatDoge" # str openSea wallet url
);
2
3
GAME.URLS.openTwitter(
"https://twitter.com/swatdoge" # str twitter url
);
2
3
GAME.URLS.openYoutube(
"https://www.youtube.com/channel/UCkQM8ePPA8me73585aLJvmw" # str youtube url
);
2
3
GAME.changeGame(
"DQ_Battleboats" # str game name
);
2
3
server-side
Getting hostWARNING
You can only retrieve host player object if player is spawned in
# Get player object of host
obj player = GAME.CONFIG.getHost();
2