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 / Handling Gamestate and Transitions

Author
Message
anwserman
12
Years of Service
User Offline
Joined: 20th May 2011
Location: Wisconsin
Posted: 15th Aug 2011 08:37
Any suggestions on how to do this with DBPro? With object-oriented languages, you'd make a base class and every state would then inherit from it. However, DarkBasic Pro does not have this luxury.

Right now, I have essentially a fixed-state machine with the code transitioning from one block to the next. All the variables I have are global, however, and I'm concerned about inadvertently using the same variable for different menus, causing debugging nightmares and the like.

What would you all suggest?

Hi there. My name is Dug. I have just met you, and I love you.
Grog Grueslayer
Valued Member
18
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 15th Aug 2011 08:53
Just don't make all your variables global. You may know this already but within functions variables that aren't global are just local to that function and do not carry their values to the rest of the program even if you use the same variable name.



Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 16th Aug 2011 20:02 Edited at: 5th Sep 2011 17:20
Anwserman,

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.

[img][/img]


WindowsXP SP1,Vista,Windows 7 DBpro v7.61
Stab In The Dark Editor
The coffee is lovely dark and deep,and I have code to write before I sleep.

Attachments

Login to view attachments
anwserman
12
Years of Service
User Offline
Joined: 20th May 2011
Location: Wisconsin
Posted: 16th Aug 2011 20:40
Wow.
That is really impressive code. I got the gist of it, but unfortunately it won't compile - I'll have to make some adjustments. But thank you very much.

It is more elegant than what I would have done... you rock.

Hi there. My name is Dug. I have just met you, and I love you.
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 16th Aug 2011 22:01
@SitDS,
Using an array of function pointers is fine, but if you only want to suspend a state and to resume it later, you can't do it without writing code to store the state and to resume it later.

When you get to that point, then coroutines are a good route to take. They are also good to use to carry out a long-running process in small steps (I've used them to construct terrain objects piecemeal from disk data, so that there's no visible delays caused by loading - not quite as good as multithreading, but usable).

BTW, you may want to put a GRAB FOCUS at the end of your StartVariableWatcher so you don't have to remember to click on the DBPro window to get it to recognise input.

Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 5th Sep 2011 17:38 Edited at: 5th Sep 2011 17:39
anwserman

We took the Game States example code that we posted here, and made it into a template project in the Stab In The Dark Editor(Alternate IDE for DBPro), which we just released in a work in progress thread. You might want to check it out on this link.


http://forum.thegamecreators.com/?m=forum_view&t=188786&b=8

[img][/img]


WindowsXP SP1,Vista,Windows 7 DBpro v7.61
Stab In The Dark Editor
The coffee is lovely dark and deep,and I have code to write before I sleep.

Login to post a reply

Server time is: 2024-04-18 19:57:41
Your offset time is: 2024-04-18 19:57:41