How to implement action sequences and cutscenes

This post will show ways of implementing actions sequences and cutscenes in video games. - Elias Daler

Possible way of doing it:

  • State machine (with a lot of if in bruteforce case)
  • Action list
  • Coroutine - combined with action list

The approach is not perfect, however. For example, it’s hard to handle saving. For example, suppose that you have a long tutorial which is just one big coroutine. The player won’t be able to save during this tutorial, because you’d have to serialize coroutine’s state and then resume coroutine exactly from the point it was paused at.

local function f()
  print("hello")
  coroutine.yield()
  print("world!")
end

local c = coroutine.create(f)
coroutine.resume(c)
print("uhh...")
coroutine.resume(c)

Which output

hello
uhh...
world

see also

caption

Written on October 5, 2024, Last update on October 6, 2024
coroutine codingame lua