From 538cb7902379ae95f10725b6fb63d1ab8dd4ce42 Mon Sep 17 00:00:00 2001 From: "False.Genesis" Date: Sun, 1 Sep 2019 22:41:51 +0200 Subject: [PATCH] Updated entity scripting (markdown) --- entity-scripting.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/entity-scripting.md b/entity-scripting.md index 971c60c..a995030 100644 --- a/entity-scripting.md +++ b/entity-scripting.md @@ -24,7 +24,7 @@ Interface functions are called by the game to notify an entity of certain events Most of them are optional; the game will try to call it and if that doesn't work, it remembers that and won't call the same function again. Beware! This means that if your interface function throws an error, it will be considered non-existent and never called again for the entity that caused the error. This is probably not what you want, so have an eye on the error log and fix your code if that happens. -If you get errors like `jellysmall : Attempt to call a nil value (???:0) animationKey` this is usually the normal clutter that appears when an interface function isn't defined. +If you get errors like `jellysmall : Attempt to call a nil value (???:0) animationKey` this is usually the normal clutter that appears when an interface function (in this case `animationKey`) isn't defined. ## List of interface functions @@ -36,10 +36,15 @@ Called once when an entity is spawned. Usually used to set health, textures, att When a map is loaded, all scripted entities on the map have their `init()` function called. When an entity is spawned dynamically while the map is already going, `init()` is called the same way. +_Warning_: Do not spawn or delete entities in `init()` as this may lead to problems. Use `postInit()` for that. + ### `function postInit(me)` Useful to set properties that depend on other entities being already inititalized. When a map is loaded, all entities' `init()` is called first, _then_ all entities' `postInit()` is called. +When an entity is spawned dynamically while the map is already going, `init()` is called first, and `postInit()` immediately afterwards. + +_Compatibility note_: `postInit()` is not called when an entity is spawned via an [[SE-node|nodes]]. ### `function update(me, dt)` __[mandatory]__