Bluestar4:
I suppose we could debate this all day lol!
Quote: "I usually place a label right before doing the code of the main menu screen. This gives me the advantage of being able to unconditionally jump directly to the main menu from anywhere in the program"
You are perfectly within your rights to use whatever programming method you like - including the use of Goto if you want. Don't get me wrong, I'm not demanding that an experienced coder changes the way they've written programs for years. (That experience allows them to avoid the dangers of using Goto that newcomers simply will not have).
You use Goto for a main menu screen. Fine - a lot do. In a procedural programming language, what I wonder is exactly
why?
It's like when you use an Object Oriented programming language, you use OOPS methodology. Goto is simply a 'legacy' command left in for compatibility and isn't a part of structured programming so I just think it's best for
newcomers to not use it.
Quote: "This gives me the advantage of being able to unconditionally jump directly to the main menu from anywhere in the program"
You could do exactly the same with Gosub and remain within the structured programming framework, so what's the advantage of using Goto?
I'm just suggesting it's a better way to have a Main_Menu procedure which contains a program control loop. This loop is never exited unless:
* The user selects 'Play Game' - at which point program control drops back to the main program loop.
* The user selects 'Exit' - at which point the program just ends.
You set up your program variables at the start then immediately Gosub the Main_Menu procedure. On exit from this, it returns and executes the main game loop. At
any time you can Gosub the Main_Menu procedure to return to the main menu and each time, selecting play drops you back to the main game loop.
Gosub Setup
Gosub Main_Menu
Rem *** Main Game Loop ***
Do
Rem All Gosubs Here Are For When The Game Is In Play
Rem If The Game Ends Then Simply Gosub Main_Menu
Sync
Loop
End
Main_Menu:
PlayGame=0
Repeat
Rem If Player Selects Screen Mode Option Then Gosub Scrn_Mode
Rem ... Continue With All Other Menu Options
Rem If Player Selects Quit Then END
Rem If Player Selects New Game Then PlayGame=1
Until PlayGame=1
Rem Program Control Reaches Here Only If Play Game Has Been
Rem Selected So Initialise Variables For New Game And Drop
Rem Out Of Main_Menu And Return To Main Game Loop
Gosub Game_Init
Return
Game_Init:
Rem Reset Variables Etc Here For A New Game
Return
Game_Setup:
Rem Set Up Screen, Variables Etc Here
Return
Scrn_Mode:
Rem Select Screen Mode Code Here
Return
This method keeps all code for any given task in it's own easily identifiable (and locatable) procedure making it easier to trace and debug.
And to me, what's important is that it doesn't need Goto and adheres to the procedural programming ethic.
TDK_Man