Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Loop Systems

Author
Message
Baneblade
22
Years of Service
User Offline
Joined: 26th Feb 2003
Location: Ireland
Posted: 26th Sep 2003 12:01
I have a question about loops in DBC.
I have a menu system that loads first when the program is run. From it I what to be able to load a matrix and objects. The best way to describe this is like the DBC FPS tutorial with a menu.
How do I leave the primary loop containing the menu system , to a second loop system, containing the game and on pressing something like the escape key return to the menu system. I have tried the GOTO and GOSUB commands but I think I am missing somethng
Thanks,
Baneblade
BatVink
Moderator
22
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 26th Sep 2003 14:11 Edited at: 26th Sep 2003 14:13
You don't leave the loop, you nest your second loop within the first. That way, as you leave each nested loop, you drop back to the previous one - the menu. It's how the majority of programs are coded, not just games.



BatVink (formerly StevieVee)
http://facepaint.me.uk/catalog/default.php
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 26th Sep 2003 17:07
i used a loop in my menu that was seperate to the main one...
there is code in the post http://www.thegamecreators.com/?m=forum_view&t=17057&b=10 which i placed there that may help...

In my posted code, to exit back to the menu, just put a tag at the very start of code:


then in the main loop of the game, have an IF like this:



the only problem with this would be that it doesnt pause the game, it actually resets everything, so your prolly best off having a seperate section of code somewhere that is a gosub with a RETURN... this way, the game is paused then it is reentered where it left off...

keep on gaming...

If Quizz's Are Quizzical, Then What Are Test's?
BatVink
Moderator
22
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 26th Sep 2003 18:59
The problem with GOTOs, unless you place it just before a LOOP, is that it's not structured programming. You'll get along fine for a while, but as soon as your program starts to grow, it will start to cause you problems.

"GOTO considered harmful", an interesting read...

http://www.acm.org/classics/oct95/

BatVink (formerly StevieVee)
http://facepaint.me.uk/catalog/default.php
KNau
22
Years of Service
User Offline
Joined: 25th Nov 2002
Location: Canada
Posted: 26th Sep 2003 23:59
For the sake of organization I recommend using seperate functions for each major code block of your game. After trying many different styles I found functions to be the most useful.

The layout is that you have a primary loop in your main file that has no actual game code in it, basically just a bunch of IF/THEN conditions and function calls. You #INCLUDE the other parts of your game code as seperate files to keep organized.

Here is an example of my "main loop" from an early version Power Mad. The code could be (and was) further refined but here is was kept very simple so I could keep better track.

Every major game function has it's own seperate function call - load_game_art(), load_game_sound(), select_character(), main_menu(), etc. It keeps your code organized and quickly portable if you want to reuse it for future projects (I reuse the same initialization and intro functions).

http://www.canceriannewmedia.com
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 27th Sep 2003 07:58
You know, that is a very good idea... It would also make it easier for game/program updates cos you wouldnt have to reaplace the entire main exe file, you could just replace the individual modules.

Thanks for that tip KNau, i will be using that in my game now...

If Quizz's Are Quizzical, Then What Are Test's?

Login to post a reply

Server time is: 2025-05-20 14:38:10
Your offset time is: 2025-05-20 14:38:10