nsensfel / tonkadur

Narrative scripting/programming tool. Write stories in your favorite editor using a feature-rich language, compile them into a very small and simple language to easily integrate them into your game.
https://tonkadur.of.tacticians.online
Apache License 2.0
3 stars 0 forks source link

Sharing memory over multiple narratives #20

Closed nsensfel closed 1 year ago

nsensfel commented 3 years ago

Currently, there is nothing put in place to facilitate using the same memory elements over multiple narratives. To do this manually, one would simply add "delete all memory elements whose name starts with ." to the (end) instruction and "do not change value if it already exists" to the (initialize ...) instruction. While it can work, it's definitely an unsafe hack:

To make this more user-friendly, we could add (shared [TYPE] {String}) alternative to (global [TYPE] {String}), which would denote variables that are shared across multiple narratives. These variables would not be allowed to have any lambda functions member, nor procedures, nor pointers to non-shared variables. (end) would thus delete all memory elements but these, and (initialize ...) should do the "do not change if it already exists" thing.

nsensfel commented 1 year ago

These variables would not be allowed to have any lambda functions member, nor procedures, nor pointers to non-shared variables.

Following the ideas presented in issue https://github.com/nsensfel/tonkadur/issues/44, this would no longer be a problem. addresses (and lambda functions) should have their narrative stack index included, making references to memory from narratives that have not been deleted acceptable.

(end) would thus delete all memory elements but these, and (initialize ...) should do the "do not change if it already exists" thing.

(end) should still end everything. Use (narrative:pop) and its variants to keep memory.

The issue is now merged with https://github.com/nsensfel/tonkadur/issues/44.