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.

Newcomers DBPro Corner / Return to Menu

Author
Message
Deep Thought 42
19
Years of Service
User Offline
Joined: 31st Jul 2005
Location: New Jersey, USA
Posted: 10th Aug 2005 05:55
I am trying to make it so that if I hit the escape key the game goes back to the main menu what am I doing wrong here?


"Winners never quit and quitters never win. But those who never win and never quit are idiots."
master programmer
19
Years of Service
User Offline
Joined: 30th May 2005
Location: 3D Space
Posted: 10th Aug 2005 06:01 Edited at: 10th Aug 2005 06:19
You need to delete the second do loop. And take the if escapekey()=1 (and all of its code) and put it inside the first do loop.

The reason being, is, when the computer reaches do, it uses that as the starting point, and when it gets to loop, it loops just from there to the do. So, you have a do loop that isn't being read, because you have a do loop before it.

Also, I believe you need to change your label menu: to _menu:. I really don't think that makes a difference, but that's just how I learned it.

Just change that code around and it should look like this:


Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 10th Aug 2005 06:23 Edited at: 10th Aug 2005 08:41
You have to turn off Darkbasics default for the escape key before you can use it... otherwise hitting escape will always end the program.

TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 10th Aug 2005 06:26 Edited at: 10th Aug 2005 06:29
That won't work. Menu isn't a procedure (no return). Even if it was, calling it recursively will eventually cause problems.

What you need is something like this:



[Edit] Oops, wasn't saying what you said wouldn't work Grog - you hadn't posted when I started typing this!

TDK_Man
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 10th Aug 2005 08:40
Scared me there for a second.
NanoBrain
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 10th Aug 2005 13:23
Deep Thought 42,

I usually set all of my code into groups, which are nested inside if statements, in which all the groups are nested inside a single loop. To clarify, the main menu(the lines of code which make it run), may be inside its own if end statement. Then, the gameplay part of your code may be inside it own if end statement. In its end, a single variable's value is checked against in each of the if statements, to see whether it equals a specific value. If so, then that group of code is ran, and only that group. This method I learned from my Visual Basic 6.0 course, back some time. I call the method, Form Focus, with the variable being named, frmfocus.

The example below also includes the Local Focus method, which is used inside each group of code. Its variable being named, lclfocus. To make things run smoother(referencing to the after-states of lclfocus), each group of code is its own function. To explain further, each form(group of code) has specific focuses(what groups/lines of code to run) within that form. I usually only use the lclfocus variable to determine if objects and images need to be loaded, or unloaded, for that form. In other words, it is a setup and close down variable. For example, you may need to load specific creatures for the next level, or images for the menu buttons.

This whole method just makes it simpler to switch to different parts of your program. It seems more versatile, in that you can connect different sections of your program together, and change the connections again, easily. This is simply done by changing the form numbers, which are essentially labeled by frmfocus.

An example of this method lays below. It is fully executable and needs no media. However, there is a slight bug when returning to the main menu.

Full Example:



+NanoBrain+
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 10th Aug 2005 17:48
Nice code snippet Nanobrain, but don't you think it's a little complicated to understand for someone who is struggling with how Do..Loop works?

That's why I kept my example as simple as it was...

TDK_Man

Login to post a reply

Server time is: 2024-09-24 01:29:37
Your offset time is: 2024-09-24 01:29:37