Best way to use functions?

Blitz3D Forums/Blitz3D Programming/Best way to use functions?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

That structure looks fine. Personally I prefer to keep my main loop really short and have everything happen within functions, but it doesn't really make any difference. I mean, in my way I'd only call one function in the main loop, but that one function calls a bunch of other functions, so it's really the same thing.


I suppose the one advantage to my approach is that you can use a Select/Case to determine which batch of functions to go to depending on the game's state. In other words, the main loop would determine if the game is on the main menu, loading a level, or playing a level, and go to the appropriate function for those updates.

pseudocode
While Not KeyHit(1)
     Select gameState
          Case 1 UpdateMenu()
          Case 2 LoadLevel()
          Case 3 UpdateGameplay()
     End Select
Wend

Function UpdateMenu()
     stuff for main menu
     if Start selected then gameState = 2
End Function

Function LoadLevel()
     load assets for level
     gameState = 3
End Function

Function UpdateGameplay()
     handle input and AI and whatnot
     if the player loses all their lives then gameState = 1
End Function