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 / Menu/Game Problem

Author
Message
Creator Of Darkness
17
Years of Service
User Offline
Joined: 4th Jan 2007
Location:
Posted: 2nd Feb 2007 20:38
I'm running Dark Basic ver. 12

I made a game that start off at a menu screen that is made out of 2D sprites. It then goes to a loading screen as all objects are loaded to the map when you press start. Once into the game you can press the escape key (which I disabled so that you cannot escape the program) and when you press it you appear at the menu screen again. I have no problem doing that. I just can't seem to get back into my game without problems. Now when I'm testing it out it runs perfectly. When I complied it as a stand alone game it creates an error when I get back into game from the menu screen once the game is already started. The error says "Runtime Error: ERROR 6". Now this doesn't mean much to me. I know the runtime error only shows up in stand alone executeables. I just can't seem to figure out what I'm doing wrong. I tried to make the buttons appear over the screen and it does the error automatically. I'm leaving and entered different loops to perform these operations. I was wondering if that was the case so I placed my menu screen code in my loop with my level code and it worked except the menu screen was behind the 3D area. (I knew it was working because when I hover the mouse over the buttons they make a sound.) I'm wondering if there's a way to get this to work without making my code super lengthy. I tried GOSUB commands and GOTO commands. I can't get it to work.

Any suggestions?
Dracula
18
Years of Service
User Offline
Joined: 7th Aug 2006
Location: DBP Recreation of Castle Csejthe
Posted: 3rd Feb 2007 14:28
can you use two separate .exe programs? one for the menu, one for the main game. Call the game .exe from the menu.exe. Might work, but might take a little more programming. but your game code will be shorter without the menu inside it.
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 3rd Feb 2007 18:11 Edited at: 3rd Feb 2007 18:12
Quote: "I tried GOSUB commands and GOTO commands. I can't get it to work."


The error you mention is raised when you run out of memory and in conjunction with the quote above to me points to you not having a grasp of procedural program layout.

Obviously without seeing your program, it's impossible to be sure, but my guess is that your program is getting into some loop you can't get out of and just eating up memory. This is one of the reasons I always suggest avoiding the Goto command like the plague!

You need to put your menu code inside a loop in a procedure which is called from your main program loop.

Here's a basic format for a game which does what you ask. There's more info on program layout in my tutorials in the stickies if you need it.



TDK_Man

Creator Of Darkness
17
Years of Service
User Offline
Joined: 4th Jan 2007
Location:
Posted: 3rd Feb 2007 20:07
Dracula, I've been considering making separate programs but I don't see how that will help.

TDK, okay so I'm running out of memory because of my program loops. That makes some sense now. I think I know how to fix the problem now.
But could I use your way to go BACK to the main menu and BACK into my game as much as I want. Take for example the game Half-Life. You can go into the main menu to save your game when you're playing or you can load or just quit and so on.
I've been able to create my menus and get it started but I can't go back and forth without the error.
When I made a GOSUB command it didn't seem to work. Could you give a more persise working if I want to press escape to access my menu DURING game play.
I've decided to post my game so far. I know there are some other things I need to work on like my timers and my physics. I made it into a Hide and Seek game to test out different things. I took off those extra things and it didn't help.
Well... maybe with the code you could help more.

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-09-25 17:29:22
Your offset time is: 2024-09-25 17:29:22