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 / Changing Gamestates efficiently?

Author
Message
kordman916
18
Years of Service
User Offline
Joined: 5th Oct 2007
Location:
Posted: 28th Jul 2013 23:43
Hey I was curious as to how one would change the gamestate (Logo->Menu->Game)

I've seen tutorials online for C++/C/Java but I'm unsure about how to apply it to Dark Basic because it lacks classes (I think)

I'm looking for an efficient way to do it without using up a bunch of memory.

AMD FX 6300 hex-core processor 3.5 GHZ
16 GB DDR3 ram, Geforce 660 Ti 2GB ram
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 29th Jul 2013 01:03
Look at your sequence

IN > LOGO > OUT
IN > MENU > OUT
IN > GAME > OUT

So get familiar with CLS, and deleting objects...

This is just one way, but if you want to use states, just use variables maybe even add a case select stack ^^

Pretty sure more 'codier' ways will follow soon

I keep forgetting which is evil GOTO or GOSUB... either way, have a clear look at all the functions of DBPro and it will hit you eventually

Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 29th Jul 2013 02:00
Both goto and gosub are evil.

3D Bang Bang 2, check it out!

My website! [href]http:\\www.TeamDefiant.co.uk[/href]
PirateJohn
14
Years of Service
User Offline
Joined: 4th Aug 2011
Location: California
Posted: 29th Jul 2013 03:09
Gosub evil??? I wouldn't know where to begin designing my game if I didn't use subroutines.
Virtual Nomad
Moderator
20
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 29th Jul 2013 05:20
Quote: "I wouldn't know where to begin designing my game if I didn't use subroutines."


same here. maybe it's a california thing.

Virtual Nomad @ California, USA . DBPro V7.7 . Matrix1Utils 05.27.12
AMD Phenomâ„¢ X4 9750 Quad-Core @ 2.4 GHz . 8 GB PC2-6400 RAM
ATI Radeon HD 3650 @ 512 MB . Vista Home Premium 64 Bit
JamesWalker101
16
Years of Service
User Offline
Joined: 14th Apr 2010
Location: England
Posted: 29th Jul 2013 11:15
I decided not to use those "evil" functions for my current game, and with my limited coding ability, I struggled, and ended up using the following code.
Stab in the Dark software
Valued Member
23
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 29th Jul 2013 16:50 Edited at: 30th Jul 2013 18:25
One method for implementation of a Game State structure in Dark Basic Pro is to construct a User Defined Data type for a Game State.
The data type for the Game State would store function pointers to functions for handling;
initialization of the Game State, cleanup of the Game State, and rendering.

An example project is attached.

Note: This example requires two third party plugins.
The links are in the main file of the project.
Edit: Here is a code snippet from the attached project



[img][/img]
[ic:coffee

WindowsXP SP3,Vista,Windows 7 SP1, DBpro v7.7RC7
Stab In The Dark Editor
The coffee is lovely dark and deep,and I have code to write before I sleep.
Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 29th Jul 2013 21:30
Quote: "Both goto and gosub are evil."

I've heard a few people claim that subroutines are bad, but I've never heard a reason why. They make code so much easier to read.
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 29th Jul 2013 21:39
I do not use Gosub (except when using a snippet that does). Only because I want to use function pointers.

Nothing wrong with using it; and perhaps you might avoid hitting the function limit (of death).

GIDustin
18
Years of Service
User Offline
Joined: 30th May 2008
Location:
Posted: 30th Jul 2013 03:32
Quote: "Nothing wrong with using it; and perhaps you might avoid hitting the function limit (of death)."


Any clue what that might be?
Burning Feet Man
18
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 30th Jul 2013 08:48
I'd be lost without Gosubs! I use both Gosubs & Functions across many .DBA files. If you think that they're evil, then they're a necessary one.

But GOTO can die in a fire... screaming.

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia
PirateJohn
14
Years of Service
User Offline
Joined: 4th Aug 2011
Location: California
Posted: 30th Jul 2013 09:17 Edited at: 30th Jul 2013 09:18
Quote: "But GOTO can die in a fire... screaming."


GOTO Fire

Fire:
INSERT SCREAMING 6, 6, 6
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 30th Jul 2013 11:57
Gosubs
Good: A good reason to use GOSUB's is because there faster than functions so their great for initialising variables or other things.

Badish: A bad reason would be lack of flexibility unlike functions, so to do a task that could be split up into function with Gosubs would mean repeating massive chucks of code making the process even longer to do.

Goto's
Good: There's only one good reason to use Goto's and that's when your a beginner programmer and don't fully understand how to handle getting to and from different bits of code.

The Really Bad: As your project get's larger so does the confusion. Goto's have no clear defining end unlike Function's and Gosubs and because a larger game will require you to access code all over the place you'll have a Goto spaghetti nightmare trying to stop Goto's codes overlapping other Goto's meaning you'll have to remember where every Goto comes from and where it goes back to which on a large game you could have thousands of Goto commands all over the place. To eliminate some of these problems you'd have to repeat massive section of code. Not fun, not worth it.

"Get in the Van!" - Van B
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 30th Jul 2013 15:09
I refer you to this: http://forum.thegamecreators.com/?m=forum_view&t=178016&b=2&p=1

And probably one of the most epic quotes ever created on TGC:

Quote: "I have a story. Once long ago I was introduced to the magical wonders of Dbpro. Grog was there to guide my foolish questions, I remember it to this day. And as my wheels got turning, I learned of the villainous GOTO. I tapped into its corruption, thinking that the power to jump for line to line would strengthen my game. And for a week or so, it did. Progress came like strawberries in summer and I the programmer spirits smiled upon me. But alas, it was all for naught, for soon there after the GOTOs rioted in the source. Their tricky logics flummoxed my very being, and sent the project hurtling towards an unknown nether world of spaghetti madness. I never saw the source code again.

Since that dreadful fate, I have forbidden myself to be tempted by the lustful GOTO command. It is evil."

- flashing snall

@ kordman916

I suggest going with a structure based on the following (I haven't looked at Chris' solution, but he's a good programmer, so perhaps he's already done this and I'm being redundant):



TheComet

Login to post a reply

Server time is: 2026-07-07 18:21:28
Your offset time is: 2026-07-07 18:21:28