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

Player choices with loops #9

Closed nsensfel closed 3 years ago

nsensfel commented 4 years ago

There should be a way to generate player choices using loops. It's pretty important for stuff like inventory management, enemy selection, and plenty of other stuff.

This presents two challenges:

nsensfel commented 4 years ago

19d1cd9 resolves the second part, but at a cost: the new strategy is that once the choice has been made, the whole player_choice is re-executed while bypassing the labels until the choice corresponding to the one made by the user is reached, at which point the associated code is executed. It works as long as re-executing the player_choice generates the same choices. Thus, for this to work properly, any conditional or loop using rand would have to be forbidden: the random values would then have to be computed prior to the player_choice construct. It's a bit annoying, but definitely much better than not being able to use loops. A new Wyrd computation had to be added, which is not great in itself, but it also simplified two Wyrd instructions (choice numbers are used outside of Wyrd instead of code lines, which simplifies thing for the user).

Making rand be deterministic on that second pass might be doable in pure Wyrd, with some register serving as a flag to indicate that rand results should be stored in a list, and another indicating that rand results should be taken from there instead. As much of a hack as it looks like, this is likely still an easier solution than somehow storing the right values for each variable that the code would otherwise need to access.

nsensfel commented 4 years ago

d68040d resolves the issue of rand, following the strategy from the previous message.

nsensfel commented 3 years ago

Also implemented a for equivalent for choices. It's a bit tricky to use compared to the usual for: