Pular para o conteúdo

How scripts work

Este conteúdo não está disponível em sua língua ainda.

GDMP experiences run sandboxed JavaScript (V8) with one global, gdmp. A script has no file or network access and cannot run code it receives from the network; everything it can do goes through gdmp.

Neon Tag's server script: touch a player to pass IT.

A package has up to three scripts, each optional:

Script Runs on Typical use
server (scripts/server/main.js) the game server the rules: authoritative, sees every player
client (scripts/client/main.js) every player’s game, in Play UI, local effects, this player’s input
build (scripts/build/main.js) the creator’s game, in Build tools that edit the level

The manifest’s "capabilities" list says what the scripts may use. A name that is not granted is simply undefined, so test for it: if (gdmp.economy) { ... }.

Namespace Server Play client Build client Capability
gdmp.version, gdmp.log, gdmp.time ✓ ✓ ✓ —
gdmp.players (queries, events) ✓ ✓ ✓ players
gdmp.players.respawn/teleport/freeze/setVisible ✓ playerControl + net + players
gdmp.nametags ✓ playerControl + net + players
gdmp.net, gdmp.state ✓ ✓ net
gdmp.zones ✓ ✓ players
gdmp.players.onTouch and friends ✓ ✓ players
gdmp.audio ✓ (sends) ✓ (plays) net + players on the server; nothing on a client
gdmp.economy ✓ (full) ✓ (promptPurchase) net
gdmp.data ✓ data
gdmp.voice ✓ (channels, mutes) ✓ (speaking, volumes) voice
gdmp.console ✓ ✓ —
gdmp.sprites ✓ nativeUI
gdmp.world (read) ✓ ✓ world
gdmp.world.create/update/remove, gdmp.build ✓ worldWrite
gdmp.level (read) ✓ ✓ level
gdmp.level.create/update/remove/transaction/getByHandle ✓ level (Build)
gdmp.level.spawn ✓ (group[, playerId]) ✓ (group) levelControl
gdmp.input ✓ input
gdmp.player ✓ playerControl
gdmp.ui ✓ ✓ nativeUI
gdmp.web ✓ ✓ webUI
  • Values a call returns are frozen copies: reading them is free, changing them throws.
  • Callbacks (on...) stay registered while the script is loaded; each kind has a limit (64 by default).
  • A bad argument throws a TypeError that names the call and what it expected, for example gdmp.players.teleport: expects (id, x, y) .... Nothing happens then.
  • Coordinates are GD level units: 30 = one block; a player standing on the ground row is at y = 105.
  • gdmp.version is the API level as a string ("103" today). Compare it as a number: Number(gdmp.version) >= 92. Versions →
  • gdmp.state: the server writes keys, every client reads them and hears changes. A player who joins late gets everything. Use it for scores, phases, who is IT.
  • gdmp.net: messages between the server script and client scripts, for events (“you got a coin”).

Next: your first script.