I have to wonder. Can I have multiple entities (NPCs and such), each with their own Lua scripts (or none, it depends on the entity), that also all share a set of common state?
Say I have the common functions dialogue and music, and a reference to the player. Buncha stuff like that. I also have NPC-specific scripts with event functions like onTrigger or onSpawn. I want each of these NPCs to have their own onTrigger functions but share the one set of common stuff.
Edit: I mean say I have an entity defined to use "alpha.lua" as its script source. On spawn, that entity loads "alpha.iua" into its own sol::state, calling the onSpawn function if it exists in that state. That function may set a bunch of "global" variables that should stay in that state, not clobbering any other entities.
But at the same time, all these individual entities with their own states should have access to a bunch of actually global stuff like common functions... that I preferably only set up once.
/edit
Can this be done in Sol2, or am I better off recreating all the common stuff for each entity's individual script?




















