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 Professional Discussion / Multiple loops - bad idea?

Author
Message
wattywatts
17
Years of Service
User Offline
Joined: 25th May 2009
Location: Michigan
Posted: 16th Jan 2013 16:20 Edited at: 16th Jan 2013 16:24
So for the new project I'm working on I was thinking it might just be easier to start a new loop for every individual level so as not to get my code so cluttered with level specific code.
Is this a good or bad idea? Also, how would I go about closing one loop and jumping to the next so the old loop isn't still running?

EDIT
I think I just answered one of my questions, looks like the Exit command will work for breaking a loop, still, is this a good idea?

http://mattsmith.carbonmade.com/
Zotoaster
21
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 16th Jan 2013 19:24
Not a good idea, because you'll have to replicate a lot of your gameplay code anyway, once for each level.

Really what you should do is find a suitable way to load and delete a level whenever necessary, and use your main loop to play the currently selected level.

"everyone forgets a semi-colon sometimes." - Phaelax
Derek Darkly
14
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 16th Jan 2013 20:12 Edited at: 16th Jan 2013 20:18
I wouldn't hard-code each level using multiple loops.

I would simply save each level's unique variables into separate data files for loading, unless the rules of each level (physics, etc.) are drastically different, in which case separate loops might be in order.

The only times I really need to stray from my main loop are:

(1)When going to a menu or something that doesn't involve the actual gameplay or
(2)When using a function or subroutine that goes right back to the main loop

D.D.
Dar13
18
Years of Service
User Offline
Joined: 12th May 2008
Location: Microsoft VisualStudio 2010 Professional
Posted: 16th Jan 2013 21:36
Quote: "So for the new project I'm working on I was thinking it might just be easier to start a new loop for every individual level so as not to get my code so cluttered with level specific code.
Is this a good or bad idea?"

The question really depends on how similar your levels are. In my current project(not in DBP), I use an appstate system where I have multiple loops instead of one large loop because a couple of my levels don't require the entirety of the gameplay code that others do, and one or two are totally different from the other levels.

Burning Feet Man
18
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 16th Jan 2013 22:43
I don't think multiple loops are a bad idea. I can see myself employing multiple loops for one technique or another in future code. And I've also read some pretty interesting articles on these forums which use multiple loops too.

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia
wattywatts
17
Years of Service
User Offline
Joined: 25th May 2009
Location: Michigan
Posted: 17th Jan 2013 02:59
I think I'll go that route then. Thanks for your input everyone!

http://mattsmith.carbonmade.com/
Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 18th Jan 2013 16:27 Edited at: 18th Jan 2013 17:03
It's okay to have multiple loops as long as there's a structure to it: you should have one main loop with other sub-loops branching off from it and returning. Your program should still flow in one big cycle (and that behaviour shouldn't be forced by gotos) but it's perfectly fine to send the program cursor off somewhere exotic for a while as long as it knows how to get back home. It's a good idea to make a sub-loop if you have lots of code for different program-states that conflicts with each other. I've seen a lot of people do this sort of thing:

Not a great example but you get the idea.

Shh... you're pretty.

Login to post a reply

Server time is: 2026-07-07 20:23:53
Your offset time is: 2026-07-07 20:23:53