Operations
Script Operations
CreateScript
Create a new C++ script file from a template.
| Parameter | Type | Required | Description |
|---|---|---|---|
script_name | string | Yes | Script name (e.g., "PlayerController") |
entity_guid | string | No | Entity to auto-attach the script to |
template_type | string | No | Template: "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.
| Parameter | Type | Required | Description |
|---|---|---|---|
new_content | string | Yes | Complete C++ source code |
script_guid | string | No | Script asset GUID (use this OR script_name) |
script_name | string | No | Script 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.
| Parameter | Type | Required | Description |
|---|---|---|---|
entity_guid | string | No | Target entity GUID (use this OR entity_name) |
entity_name | string | No | Target entity name |
script_guid | string | No | Script GUID (use this OR script_name) |
script_name | string | No | Script name |
{
"op": "AttachScript",
"params": {
"entity_name": "Enemy",
"script_name": "EnemyAI"
}
}
DetachScript
Remove a script from an entity.
| Parameter | Type | Required | Description |
|---|---|---|---|
entity_guid | string | No | Target entity GUID (use this OR entity_name) |
entity_name | string | No | Target entity name |
script_guid | string | No | Script GUID (use this OR script_name) |
script_name | string | No | Script 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.
| Parameter | Type | Required | Description |
|---|---|---|---|
script_guids | array | No | Specific 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": {}
}
]