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: llms-full.txt
+73Lines changed: 73 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -2231,6 +2231,79 @@ editor.transact({
2231
2231
print(editor.can_reset(node_in_template, "text")) -- true (overrides a value in the template)
2232
2232
```
2233
2233
2234
+
#### Editing game objects
2235
+
2236
+
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:
2237
+
```lua
2238
+
editor.transact({
2239
+
editor.tx.add("/npc.go", "components", {
2240
+
type = "sprite",
2241
+
id = "view"
2242
+
}),
2243
+
editor.tx.add("/npc.go", "components", {
2244
+
type = "collisionobject",
2245
+
id = "collision",
2246
+
shapes = {
2247
+
{
2248
+
type = "shape-type-box",
2249
+
dimensions = {32, 32, 32}
2250
+
}
2251
+
}
2252
+
}),
2253
+
editor.tx.add("/npc.go", "components", {
2254
+
type = "component-reference",
2255
+
path = "/npc.script"
2256
+
id = "controller",
2257
+
__hp = 100 -- set a go property defined in the script
2258
+
})
2259
+
})
2260
+
```
2261
+
2262
+
#### Editing collections
2263
+
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
2299
+
}
2300
+
}
2301
+
})
2302
+
})
2303
+
```
2304
+
2305
+
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.
2306
+
2234
2307
### Use shell commands
2235
2308
2236
2309
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:
Copy file name to clipboardExpand all lines: 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
@@ -430,6 +430,79 @@ editor.transact({
430
430
print(editor.can_reset(node_in_template, "text")) -- true (overrides a value in the template)
431
431
```
432
432
433
+
#### Editing game objects
434
+
435
+
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:
436
+
```lua
437
+
editor.transact({
438
+
editor.tx.add("/npc.go", "components", {
439
+
type="sprite",
440
+
id="view"
441
+
}),
442
+
editor.tx.add("/npc.go", "components", {
443
+
type="collisionobject",
444
+
id="collision",
445
+
shapes= {
446
+
{
447
+
type="shape-type-box",
448
+
dimensions= {32, 32, 32}
449
+
}
450
+
}
451
+
}),
452
+
editor.tx.add("/npc.go", "components", {
453
+
type="component-reference",
454
+
path="/npc.script"
455
+
id="controller",
456
+
__hp=100-- set a go property defined in the script
457
+
})
458
+
})
459
+
```
460
+
461
+
#### Editing collections
462
+
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
498
+
}
499
+
}
500
+
})
501
+
})
502
+
```
503
+
504
+
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.
505
+
433
506
### Use shell commands
434
507
435
508
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