You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/en/manuals/editor-scripts.md
+73Lines changed: 73 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -409,6 +409,79 @@ editor.transact({
409
409
print(editor.can_reset(node_in_template, "text")) -- true (overrides a value in the template)
410
410
```
411
411
412
+
#### Editing game objects
413
+
414
+
It's possible to edit components of a game object file using editor scripts. The components come in 2 flavors: referenced and embedded. Referenced components use type `component-reference` and act as references to other resources, only allowing overrides of go properties defined in scripts. Embedded components use types like `sprite`, `label`, etc., and allow editing of all properties defined in the component type, as well as adding sub-components like shapes of collision objects. For example, you can use the following code to set up a game object:
415
+
```lua
416
+
editor.transact({
417
+
editor.tx.add("/npc.go", "components", {
418
+
type="sprite",
419
+
id="view"
420
+
}),
421
+
editor.tx.add("/npc.go", "components", {
422
+
type="collisionobject",
423
+
id="collision",
424
+
shapes= {
425
+
{
426
+
type="shape-type-box",
427
+
dimensions= {32, 32, 32}
428
+
}
429
+
}
430
+
}),
431
+
editor.tx.add("/npc.go", "components", {
432
+
type="component-reference",
433
+
path="/npc.script"
434
+
id="controller",
435
+
__hp=100-- set a go property defined in the script
436
+
})
437
+
})
438
+
```
439
+
440
+
#### Editing collections
441
+
It's possible to edit collections using editor scripts. You can add game objects (embedded or referenced) and collections (referenced). For example:
__hp=100-- set a go property defined in the script
477
+
}
478
+
}
479
+
})
480
+
})
481
+
```
482
+
483
+
Like in the editor, referenced collections can only be added to the root of the edited collection, and game objects can only be added to embedded or referenced game objects, but not to referenced collections or game objects within these referenced collections.
484
+
412
485
### Use shell commands
413
486
414
487
Inside the `run` handler, you can write to files (using `io` module) and execute shell commands (using `editor.execute()` command). When executing shell commands, it's possible to capture the output of a shell command as a string and then use it in code. For example, if you want to make a command for formatting JSON that shells out to globally installed [`jq`](https://jqlang.github.io/jq/), you can write the following command:
0 commit comments