to expand on nonzero's post
I'd suggest placing 'everything' in your main loop, but very little other than calling functions. I.E.
Do
Menu(catagory$,selection$)
PlayerMovement()
WeaponControl()
Projectiles()
NetCode("server")
Sync
Loop
function Menu(catagory$,selection$)
if catagory$="mainmenu"
text 0,0,"Main Menu"
if selection=1 then text 0,100,"This would be to start Single Player"
if selection=2 then text 0,120,"This would be to start Multiplayer"
endif
if catagory$="lobby"
// and so on
endif
endfunction
function NetCode(state$)
if state$="server"
// check for any pending data from clients, apply changes as necessary
// collate all data and send it to clients
// forward any chat messages from clients back out to other clients
endif
if state$="client"
// check for data from server, modify position, angle, health etc if indicated by server
// send/check chat messages
// send current position, heading, velocity, weapon firing states and so on
endif
endfunction
This is my preferred method of doing things for several reasons
1) it keeps everything CLEAN and compact
2) it's all catagorised, so if you have any problems with the chat window for instance, go to the relevant section in the function
3) anything can be done at any point in time. You don't need to write seperate code to display the chat window ingame, or in the lobby screen for instance. All you need to do is set a variable/boolean to tell your program whether it should or shouldn't be visible right now
4) gets you into the habit of writing more dynamic functions, I like to call a menu function even when I don't intend on showing a menu. The function itself will determine what should or shouldn't be displayed at any point in time, and NOT my main code. For instance the chat window in my game can be displayed at 2 different points, either ingame or at the lobby screen. Now when i'm at the lobby screen the chat window is much larger, holds more text and doesn't disappear. Ingame it's smaller, in a different position and disappears 7 seconds after the last message was received. I don't run a seperate function, instead the function checks to see where I am and alters everything accordingly by itself
5) it's much easier to expand on your game later on. If done correctly you shouldn't need to rewrite a whole bunch of code just to add in an extra menu, support different resolutions, have more enemies running around and so on