Preserving and switching states for entities

Ayep. I hope my hearthlings won’t set anyone on fire.

Things appear to be more complicated than I thought.
Commands can be of two types - those that have an action “fire_event” and those that “call” functions.
I can’t find anything on events, but I found where are those functions they call. Unexpectedly, not in the component. Or, more precisely, in the component, but they are not called from a command directly.

{
   "type": "command",
   "name": "call_trader",
   "display_name": "i18n(stonehearth:data.commands.call_trader.display_name)",
   "description": "i18n(stonehearth:data.commands.call_trader.description)",
   "disabled_description": "i18n(stonehearth:data.commands.call_trader.disabled_description)",
   "icon": "file(call_trader.png)",
   "action": "call",
   "function": "call_trader_command",
   "object": "stonehearth.shop",
   "args": [
   ]
}

The “call_trader_command” is not situated in the shop_component. Instead it is a proxy situated in /services/server/shop/shop_service.lua. This function is the one that finally addresses the component and calls its function.
Why is it done like that, I have no idea. I suppose Radiant had their reasons. Maybe it is something related to multithreading.

PS.

function frostfeast:_three_headed_monkeys()
   local victim = radiant.mods.require('stonehearth.services.server.game_master.controllers.encounters.script_encounter')

The thing I love about programmers is their sense of humor.

Edit: found this comment by @sdee on firing events. It’s horribly outdated, but I now suspect events are handled not through server/client services but through call_handlers. The only thing that confuses me is that event name in command JSON and in manifest is different. For example, where JSON uses “radiant_place_item”, manifest lists only “place_item” function (that references the appropriate call handler).

Edit2: boop @RepeatPan. Because I can. Maybe he knows something.

Edit3: there are not 2 but 3 types of commands.

  • firing events
  • calling function on object (service)
  • calling function from manifest (stonehearth:function_name)