This is instance of a broader topic, but I concentrate on a narrow example.
Imagine a jRPG (like Final Fantasy 6 or Tales of Phantasia). A game like this generall has a lot of cutscenes.
Logic of cutscenes lends itself nicely to a simple sequentual description:
hero.walk(0,-100);
npc.walk(0,100);
say("Hero","I will need to travel north. Do you know how I may go about it?");
say("NPC","There is a bridge to the north. I can open it for a 1000 coins.");
if(money<1000)
{
say("Hero","Drat!");
}
else
{
if(choice("How about it","1. Yes","2. Not now"))
{
say("NPC","Opening right away!");
money-=1000;
tile(10,10).passable=true;
}
else
{
say("NPC","See you later!")
}
}
I am combining quests and cutscenes here, but if we are using scripting language, it feels natural thing to do.
If we are writing a text-based game (text quest), this is actually how we can implement it.
However if we are writing a video-game, things are different. We usually have an update()/render() loop, and need to draw things on screen 60 times a second.
So there are two subsystems: cutscenes, which are nice and sequental, and game engine, which is nice and wants to run update()/render() 60 times per second.
Is there a way to make them communicate cleanly?
Our options are:
1. Cutscenes system is in control. walk(), etc. actually call render() inside, and so on. Strange, and raises some questions: how do we go back to normal gameplay? Or "normal gameplay" is also a kind of a cutscene? Etc.
2. Use actual separate thread. This feels like a wrong tool for the job. The interaction between engine and cutscene subsystem better be deterministic/synchronized, probably.
3. Use some form of coroutines. This feels like the right thing, but how to go about it, exactly? What walk() should look inside? If we are using e. g. Lua (having your own scripting language with full control might simplify this). And how engine runs cutscene?
4. Ditch scripting and write cutscenes in C++. Saves the need to write communication layer, and probably can be made not to blow up compilation time. But does not answer the main question: how to sequental cutscene.
5. Use state machines. Workable, but not nice. More code, less natural flow, more demand for coding experience for scripter.
There are few open-source jRPGs. Valyria Tear seems to use state machine kind of approach. Which feels like a waste, considering Lua has coroutine support.
So, I guess, the question is:
1. Do you know a clean way to do this?
2. How did people go about this? There are a lot of jRPGs. Cutscenes have been done for years. How does this look in games? Examples of scripts from actual games are welcome (assuming it is legal to post them). Not necessary jRPG. Baldur's Gate? WoW?
Broader topic (from the beginning of the question): this interaction seems common and kind of a pain (I'm guessing that for typical Match-3 the code to implement actual logic (sufficient for ASCII console Match-3) is dwarfed by the code to get gameplay animated). And intuition is, that it does not need to be.