giovinazzo-kevin / Fiero

1 stars 0 forks source link

Script Context, Messaging and Global Storage #17

Closed giovinazzo-kevin closed 8 months ago

giovinazzo-kevin commented 1 year ago

Scripts should have some information available to them regarding their creation context. This context should be an object with an arbitrary shape, as each script will have specific requirements. It can simply be represented as the act of asserting a bunch of facts at script initialization time.

Scripts should be able to message other scripts through the same event-driven infrastructure that's already being used for game events. Specifically, the scripting system should provide a meta-event that scripts can subscribe to and that echoes any message sent by any script. Then, the scripts can simply listen for messages directed at them via pattern matching:

:- module(test, []).
:- subscribe(scripting, [message_sent]).

scripting:message_sent(event_name {  from: Sender, to: test, content: 'Hello' }) :-
    Sender \= test,
    send_message(event_name { from: test, to: _, content: 'World!' } ).

Additionally, a shared knowledge base should be available to all scripts. This knowledge base would contain facts about the current state of the game world while providing a transactional interface for scripts to manipulate this information concurrently. It would be separate from the script's own knowledge base, however.