Profile Scripts

Overview

Profile scripts contain the game logic executed by the Profile server. Scripts are written in daScript and run in response to JSON-RPC requests from the game client or other services.

For a full introduction to writing scripts, see the .


Adding Profile Scripts

To use profile scripts, you need to:

  1. Upload a scripts archive to the profile scripts config.

  2. Deploy configs to services.


How Scripts Work

The Profile server executes actions – functions defined in daScript that run in response to JSON-RPC requests from the game client or other services. Actions for the same profile are always executed sequentially.

The player profile is stored in MongoDB but cached in memory for performance. On the first action for a profile, it is loaded from the database into memory. While the profile remains cached, subsequent actions run against the in-memory state without a database round-trip. The profile is eventually persisted back to the database and evicted from the cache. If a new action arrives after eviction, the load cycle repeats.


Script Structure

A typical scripts setup consists of:

  • profile.das – defines the persist struct that holds the player’s profile state.

  • config.das – reads the profile config using load_server_config and exposes it as a typed constant.

  • actions/ – one or more files containing JSON-RPC action definitions.

Defining Profile State

options gen2
require jsonrpc

struct PlayerProfile {
  level : int
  xp : int64
}

var persist : PlayerProfile

Reading Config

options gen2
module config public
require jsonrpc

struct Config {
  maxLevel : int
  levelUpXp : int64
}

let shared config <- load_server_config(Config())

Writing Actions

options gen2
require jsonrpc
require profile
require config

[jsonrpc_method]
def add_xp(delta : int64) {
  if delta <= 0 {
    send_error("delta must be positive")
    return
  }
  persist.xp += delta
  while persist.level < config.maxLevel && persist.xp >= config.levelUpXp {
    persist.level += 1
    persist.xp -= config.levelUpXp
  }
  send_result(persist)
}

JSON-RPC Actions

Actions are functions annotated with [jsonrpc_method]. By default, an action is a profile action: the player profile is loaded and locked for the duration of execution.

See the for the full list of available annotations and built-in functions.


ProfileLib Modules

The profilelib library provides reusable helpers for common patterns:

Module

Description

profilelib.jsonschema

Generates JSON Schema builders for daScript structs.

profilelib.jsonschema_jsonrpc

Automatically exposes schema endpoints for JSON-RPC methods.

profilelib.profile_schema

Splits profile state into typed parts with [profile_schema]

profilelib.rollback_on_error

Rolls back persist mutations when an action sends an error.

profilelib.unique_transaction

Makes actions idempotent by deduplicating transaction IDs.

profilelib.static_data_json

Loads and deserializes JSON files into typed daScript structs.

profilelib.macros

Base AST helpers for writing custom function annotations.

See the for full documentation on each module.