News for hackers. Stuff that matters.
Re:Coroutines and Fibers: Why and When by vvanders on Friday January 15, 2016 @03:56PM (#10912087)
Coroutines are also fantastic for scripting Game AI:

  local player = nil
  while(player == nil) do
    yeild(0)
    player = LookForPlayer(...)
  end
  
  while(WalkTowardsPlayer(player)) do
    yeild(0)
  end

  while(!PlayerDead(player)) do
    MeleePlayer(player)
    yield(0)
  end
Makes state management super-simple and is something you can easily teach to designers as well. This is partly why you see Lua show up in so many game engines.
Re:Coroutines and Fibers: Why and When by striking on Friday January 15, 2016 @05:34PM (#10912783)
FSM may be a better fit for this specific application, though.
Re:Coroutines and Fibers: Why and When by vvanders on Friday January 15, 2016 @05:59PM (#10912921)
For something engineered, sure.

However if you're working with designers who don't have a lot of formal education it's much easier to convey the concept of a function that "pauses" where yield() happens.

Also quite a bit of gameplay code ends up as throw-away so being able to quickly put behaviors together is a plus.

Re:Coroutines and Fibers: Why and When by striking on Sunday January 17, 2016 @03:04PM (#10920791)
You're saying a tree of FSM states is more difficult to convey than linearized coroutine code, with emphasis on informal programmers/designers?

You may want to take a look at visual FSM solutions, which do what you specify and more, easily.

You're not even wrong.

https://unity3d.com/learn/tutorials/modules/beginner/animati..., for an example in an Animation program