Working with AI
The tgDebug API
Reference for window.tgDebug, tgInput and tgImport, the JavaScript surface that agents and scripts use to drive the web editor.
All functions are synchronous unless marked async, and they return parsed JSON. Names
are as they appear in the browser; a missing function means your editor build predates it
(tgHasExport('tg_debug_…') checks).
Scene & simulation
| Call | Returns / does |
|---|---|
tgDebug.scene() | {current:"Assets/Scenes/X.tgscene", sceneGeneration} |
tgDebug.sceneLoad(path) | queues a load. Poll scene() until current matches. |
tgDebug.sceneSave(path?) | saves the open scene (or to path) → {ok, path, entities, skipped, bytes} |
tgDebug.unsaved() | {any, reasons:[…], sceneSwitch:{…}}: what a reload would lose |
tgDebug.persistence() | which storage tier holds your files (opfs or memfs), and whether it's durable |
tgDebug.simState() | {running, bound, playSession} |
tgDebug.simPlay() / simPause() / simToggle() / simStop() | Play / Pause / toggle / Stop (Stop restores the authored world) |
Entities
| Call | Returns / does |
|---|---|
tgDebug.entities() | {entities:[{id,name}]} |
tgDebug.entity(nameOrId) | {id,name,alive,visible,archetypes,parent,position,world,rotation,scale,velocity,angularVelocity} |
tgDebug.entityCreate(primitive) | 'Cube' | 'Sphere' | 'Cylinder' | 'Capsule' | 'Wedge' | 'Quad' → {ok,id,name,undoable} |
tgDebug.entityVelocity(id,x,y,z) | sets a velocity |
tgDebug.selection() / selectByName(name) | read / set the Inspector's entity ('' clears it) |
tgDebug.archetype(table, column?) | does a DoDB table / column exist, and how many rows it has |
Script Editor
| Call | Returns / does |
|---|---|
scriptEditorShow(open?) | open / close the window |
scriptEditorCreate(name) | new Assets/Scripts/<name>.tgscript, opened |
scriptEditorOpen(path) | open an existing script |
scriptEditorText() | the full text form (string) |
scriptEditorCommit(text) | replace the graph from text → {ok, errors:[{line,message}], nodeCount} |
scriptEditorCompile() | {ok, refusalCount}. Then read scriptEditorState().refusals. |
scriptEditorSave() | {ok, runtimePath} |
scriptEditorState() | nodes, edges, compileOk, compileError, handlers, refusals, dirty |
scriptEditorNodeAdd(type,x,y) / NodeDelete(id) / NodeMove(id,x,y) | graph edits |
scriptEditorConnect('3:out','5:a') / Disconnect(to) | wires (<nodeId>:<pin>) |
scriptEditorTab('Graph'|'Text'|'Split') | switch view |
tgDebug.scriptState() | the runtime: scripts loaded and failed, calls made, the first refusal |
Attaching a script to an entity has no dedicated call. Put -Script:<path> on the entity in
a scene file and import it, or click the Inspector's Script slot (tgDebug.widget('Inspector.ScriptSlot')).
Pixel Art
| Call | Does |
|---|---|
pixelartNew(w,h) | new canvas |
pixelartOpen(path) | open an image or .tgpx |
pixelartColor(r,g,b,a) | set the brush colour (0–1) |
pixelartPixel(x,y) | paint one pixel with the current tool and colour |
pixelartGetPixel(x,y) | read one pixel |
pixelartSave(path) | .png or .tgpx → {ok, path, uuid, status} |
pixelartState() | the full editor state |
Painting a 16×16 coin from code:
tgDebug.pixelartNew(16, 16);
tgDebug.pixelartColor(1, 0.8, 0.1, 1);
for (let y = 3; y < 13; y++) for (let x = 3; x < 13; x++) tgDebug.pixelartPixel(x, y);
tgDebug.pixelartColor(0.75, 0.5, 0.05, 1);
for (let i = 3; i < 13; i++) { tgDebug.pixelartPixel(i, 3); tgDebug.pixelartPixel(i, 12); tgDebug.pixelartPixel(3, i); tgDebug.pixelartPixel(12, i); }
tgDebug.pixelartSave('Assets/Textures/coin.png'); // → {ok:true, uuid:"…"}Project & assets
| Call | Returns / does |
|---|---|
projectAssets(folder) | the Project panel's listing: {entries:[{name,path,uuid,type,residency}]} (use 'Assets/Scenes', not 'Scenes') |
projectResidency(path) / projectFetch(path) | whether a streamed asset is downloaded / start downloading it |
assetCatalogue() | the UUID ↔ path catalogue |
shaderInputs(name) | the material parameters a shader offers |
Editor UI
| Call | Returns / does |
|---|---|
widget(name) | page rectangle of a named widget: {x,y,w,h,centerX,centerY,enabled}. For example Toolbar.Play, Menu.File, File.NewScene, Inspector.AddComponent, Inspector.ScriptSlot, Hierarchy.Context.Ui, Simulation.Content, Panel.Inspector. |
popOut(panel) / dockBack(panel) | move a panel into its own window and back |
metrics() / perf() | fps, draw calls, triangles, timings |
Input: window.tgInput
tgInput.key('w', true); // hold W (names: w a s d q e space escape shift ctrl up down left right, or a GLFW key code)
tgInput.key('w', false); // release
tgInput.tap('space'); // press and release over two frames
tgInput.mousePos(x, y); // engine mouse position
tgInput.clear(); // release everythingImport: window.tgImport (async)
const file = new File([sceneText], 'MyLevel.tgscene');
const r = await tgImport.importFiles([file], 'Assets/Scenes');
// r → {ok, imported:[{path, uuid, primary}], refused:[[name, reason]], warnings:[…]}Pass images together with their .mt sidecars (as separate Files) to keep their UUIDs.
Frames
The engine runs on requestAnimationFrame. When the tab is hidden, the browser slows it to
about 1 fps. Module._tgWebRunOneFrame() advances one frame by hand, which is useful in
automation to apply a queued change immediately.