I was thinking of how I was going to structure the flow of my game and I began to think how one state could move to another.
Of course, you could run a function, have it fully execute and complete, and then carry on, but what if the function can't efficiently reach it's end?
Say I had 3 functions:
function Menu()
--Allows user to engage in game. Calls Game() to start
end
function Game()
--User plays a game until the game until GameOver()
end
function GameOver()
--User ends game and goes back to Menu()
end
If you notice, each function calls each other. If this behavior were put in action, it would be an infinitely long function
Menu()
Game()
GameOver()
Menu()
Game()
GameOver()
Menu()
....
So if you call Menu, you won't ever get past that function call
Menu() --function call, starts game
print("HI MOM") --this code is never reached
Is this a good practice to run such a system, or is there an alternative way to structure game flow?

2 comments
Why is a coroutine required?
so the
print("HI MOM!")would print.