Razorbill
Operations

Script Operations

CreateScript

Create a new C++ script file from a template.

ParameterTypeRequiredDescription
script_namestringYesScript name (e.g., "PlayerController")
entity_guidstringNoEntity to auto-attach the script to
template_typestringNoTemplate: "empty" (default), "component", or "system"

Creates Content/Scripts/<name>.cpp and Content/Scripts/<name>.scriptasset.

{
  "op": "CreateScript",
  "params": {
    "script_name": "EnemyAI",
    "template_type": "empty"
  }
}

WriteScriptContent

Write C++ source code to an existing script file. The content must follow the script template pattern with OnStart, OnUpdate, OnDestroy functions.

ParameterTypeRequiredDescription
new_contentstringYesComplete C++ source code
script_guidstringNoScript asset GUID (use this OR script_name)
script_namestringNoScript name (for scripts created in same transaction)
{
  "op": "WriteScriptContent",
  "params": {
    "script_name": "EnemyAI",
    "new_content": "#include <eng/sdk/script_context.hpp>\n\nextern \"C\" {\n\nvoid OnStart(ScriptContext* ctx) {\n    ctx->log_message(ctx, \"Enemy initialized\");\n}\n\nvoid OnUpdate(ScriptContext* ctx) {\n    float dt = ctx->get_delta_time();\n    float pos[3];\n    ctx->get_position(ctx->self, pos);\n    pos[0] += dt;\n    ctx->set_position(ctx->self, pos);\n}\n\nvoid OnDestroy(ScriptContext* ctx) {}\n\n}"
  }
}

AttachScript

Attach a script to an entity's ScriptComponent. Creates a ScriptComponent if one doesn't exist.

ParameterTypeRequiredDescription
entity_guidstringNoTarget entity GUID (use this OR entity_name)
entity_namestringNoTarget entity name
script_guidstringNoScript GUID (use this OR script_name)
script_namestringNoScript name
{
  "op": "AttachScript",
  "params": {
    "entity_name": "Enemy",
    "script_name": "EnemyAI"
  }
}

DetachScript

Remove a script from an entity.

ParameterTypeRequiredDescription
entity_guidstringNoTarget entity GUID (use this OR entity_name)
entity_namestringNoTarget entity name
script_guidstringNoScript GUID (use this OR script_name)
script_namestringNoScript name
{
  "op": "DetachScript",
  "params": {
    "entity_name": "Player",
    "script_name": "OldController"
  }
}

CompileScripts

Compile C++ scripts to dynamic libraries. Can compile specific scripts or all scripts in the project.

ParameterTypeRequiredDescription
script_guidsarrayNoSpecific script GUIDs to compile (empty = compile all)
{
  "op": "CompileScripts",
  "params": {}
}

Full Script Workflow Example

Create a script, write behavior, attach to entity, and compile — all in one transaction:

[
  {
    "op": "CreateEntity",
    "params": { "name": "Spinner" }
  },
  {
    "op": "CreatePrimitive",
    "params": {
      "primitive_type": "Cube",
      "entity_name": "Spinner"
    }
  },
  {
    "op": "CreateScript",
    "params": { "script_name": "SpinScript" }
  },
  {
    "op": "WriteScriptContent",
    "params": {
      "script_name": "SpinScript",
      "new_content": "#include <eng/sdk/script_context.hpp>\n#include <cmath>\nextern \"C\" {\nvoid OnStart(ScriptContext* ctx) {}\nvoid OnUpdate(ScriptContext* ctx) {\n    float dt = ctx->get_delta_time();\n    float rot[4];\n    ctx->get_rotation(ctx->self, rot);\n    float a = dt * 2.0f;\n    float s = sinf(a*0.5f), c = cosf(a*0.5f);\n    float nr[4] = {rot[0]*c+rot[2]*s, rot[1]*c+rot[3]*s, rot[2]*c-rot[0]*s, rot[3]*c-rot[1]*s};\n    ctx->set_rotation(ctx->self, nr);\n}\nvoid OnDestroy(ScriptContext* ctx) {}\n}"
    }
  },
  {
    "op": "AttachScript",
    "params": {
      "entity_name": "Spinner",
      "script_name": "SpinScript"
    }
  },
  {
    "op": "CompileScripts",
    "params": {}
  }
]

On this page