Build 566 Observer Clarification

In the notes:
For modders: Added way to specify default list of observers on observers component instead of needing to make an empty AI pack.

Can we get a point into the direction on how this is done?

I believe that before, we didn’t have an “observers” component per se, so if we wanted an entity to have an observer, we had to use an ai_pack, even if the ai_pack didn’t have any actions, just the observer.

So now, we won’t need to create something like this:

{
   "type": "ai_pack",
   "observers": [
      "mymod:observers:myobserver"
   ]
}

and inject the ai_pack in the entity’s json file:

"entity_data": {
      "stonehearth:ai_packs": {
         "packs": [
            "mymod:ai_pack:my_ai_pack"
         ]
      }
}

but instead we will be able to use an “observers” component in the components list of the entity’s json file.
I don’t know if this is the correct syntax, but looking at the code it sounds it might be something like this:

"components": {
	"stonehearth:observers" : {
                "default_observers": {
		       "my_mod:my_observer" : true,
		       "stonehearth:other_observer" : false
                }
	}
}

Paging @yshan for clarification (although I’m not sure who coded this :sweat: )

2 Likes

Yes, you are correct.
I edited your post a little bit for the new syntax for the observers.
This is for observers that aren’t ai_pack related (EX aren’t linked to any ai you’d want on an entity).
If your entity has AI, you can use the ai_pack method.

The reason I made it so you can have default observers is because with the ai pack method, it assumes that everything that has observers also has ai. Ai can be potentially expensive. If you just want to attach a script to something that doesn’t have to think/be intelligent (EX the stonehearth:observers:kill_at_zero_health observer on doors and loot chests), the default observers method is easier and more performant.

Thanks
-Yang

2 Likes

Cool, thanks both of you.