2 Step Forwards, 1 Step Back

Blitz3D Forums/Blitz3D Programming/2 Step Forwards, 1 Step Back

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.

What i've been doing more and more often is creating my function away from my main code. I also make sure my functions rely very little on global variables. Then, if something is breaking, you can narrow it down and thoroughly test the function away from the main code.

Another good tip i got once, was to make sure your functions were never greater than the height of the page, so you can see the whole function.

Erm, something else i do is to use a game mode variable, not just for games though. The main loop would consist of something like:


If mode = 1 then
   Show_Menu()
ElseIf mode = 2 then
   Load_level(current_level)
ElseIf mode = 3 then
   Main_Game(Main_Mode)
ElseIf mode = 4 then
   Splash_loading_screen()
ElseIf mode = 5 then
   End Credits()
End if


Where the Main_Game() function would have more modes inside it:


Function Main_Game(Main_Mode)

   If Main_Game = 0 then
      Play_Game()
   ElseIf Main_Game = 1 then
      Play_cutscene()
   ElseIf Main_Game = 2 then
      Pause_game()
   ElseIf Main_game = 3 then
      Show_Inventory()
   End If

End Function


And again, each of the modes above would have their own modes within the functions. Simplify your code and sticks specific bits of code into functions. It saves commenting your code too.


;this code does something
for loop = 1 to 10
   do stuff
   do more stuff
   if loop2 = 1 to number
      check stuff
   next
next
; --------------------------



You could easily stick that into a function, and just write:

Do_Stuff() ; this code does something


Makes it far easier to read, and miss out too, if your trying to sort problems using the debugger.

Hope some of that helps. It's pretty standard stuff, but that's what helps in my opinion :o)