The question is quite abstract, but I'll try to answer.
The concept you might need is called “Promise” (or “Future”). The idea is that instead of returning chosen value, get_dialogue_choice
immediately returns an object, namely “promise object”. Think of it as a box with a value (instead of the value).
The trick is that the box is empty when the function is returned - the player haven't chosen the value yet. The value actually appears when the choice is made.
How the value is delivered there; how the script is notified about that and how it actually behaves - is up to the implementation. Usually, promise objects can be queried for the existence of the value (.is_ready()
- “box is ready, and has a value inside?” ); and queried for the value itself (.get()
– “unpack the box”).
Now you can see how a promise-compatible “if (x == “constant”) { return A; } else { return B; }” function would look like and how. It would accept a boxed object (x
); return a boxed object (containing either A
or B
), but which one exactly is not decided upon return. Once x
is resolved; then this box can be resolved as well, becoming A
or B
(and propagating resolution chain further).
This pattern lets your code execute immediately (storing a chain of “what to do next” list) and actually perform the code later.
Implementing it is a nice exercise, but I suggest you not to try to apply all above “as is” in C++. I would advice you using an existing scripting system that supports what you want (if still want to be fancy: wrangle JS engine, for example V8, to do that: promises are common in JS, for example your trusty fetch returns one)