News for hackers. Stuff that matters.
Re:Using Lua coroutines to create an RPG dialogue system by nine_k on Tuesday January 10, 2017 @03:45PM (#13368808)
Coding a state machine manually is indeed suboptimal.

Computers are good at generating code. If you want a very fast FSM, they will build it for you from a compact representation (cf. a regex).

But for game dialogs speed is probably a secondary concern. I suspect that a table-driven FSM interpreter with a fully transparent internal state that can be saved / loaded is not very hard to create. Your dialogs' input language becomes the control table, which is possibly no less designer-friendly than Lua coroutines.

Re:Using Lua coroutines to create an RPG dialogue system by optionalparens on Tuesday January 10, 2017 @07:59PM (#13370856)
Speed is not always a secondary concern for dialog. Certainly in many games where the dialog is very fixed, sure. However more and more, dialog systems actually need to be pretty fast. The simplest reason is you generally have only a few or even 1 frame to process dialog and you certainly don't want it tying up your frame's update cycle. It's easy enough most of the time as a place where you can shave off time with some good optimizations anyway for simpler cases.

An example I see a lot where it needs to happen fast is spatial queries or AI-related dialog. For instance if I walk by someone or something, that has to trigger a query on the dialog engine for someone to say something to the player. It's not just the dialog, but the sound assets, playback, etc. that need to happen and they need to happen in a way that isn't annoying - i.e. player is far away already before dialog starts or has to "wait" in place.

Sometimes as I mentioned, AI also gets thrown into the mix in different ways. The simplest is that you want some piece of dialog to be triggered by some other game states - ex: if player killed dragon, say this, otherwise say that. It seems simple, but when you start throwing in lots of world states like in open world games and want some decent variation and natural dialog that isn't awful and repetitive, it gets harder. Now add on spatial and other requirements for a dialog query and things start to suck. To this end, it's why a lot of dialog systems suck. It's not just laziness, rather sometimes people actually can't get their dialog systems to work fast enough during update cycles and end up dropping features because of the cost vs. benefit for most games.

Dialog seems simple, but is surprisingly complicated in the greater ecosystem of other game systems. But again, this depends on the game and if you just have a side-scroller where you repeat the same 5 catch phrases, then yeah, dialog is simple and speed is not a problem.