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 / Program Reset?

Author
Message
Deego
16
Years of Service
User Offline
Joined: 21st May 2008
Location:
Posted: 18th Oct 2008 07:51
Is there a way to reset a program? I'd like to have the same effect as closing the program and restarting it, only without having to close the program first. I have a ton of sprites and variables and arrays to reset to initial values. Would the best way to do this be to call GOTO 1 when I want to reset? But then I'd still have to go through and hide or delete the old sprites, and certain variables and arrays would be messed up.

I feel this would be an easier task if I'd been keeping track of everything I'd need to do to reset the game, but 5000 lines of code later it just seems too daunting a task. Lesson learned, I guess.

If there isn't a system for reinitializing a program, would a second program that launches the game program be feasible? That way I can simply end the game program, and since the second program will be running already, it can open the game program again.
Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 18th Oct 2008 10:21
Hm... surely, you wouldn't need to reset all variables, right?

For arrays, you could just re-declare them like so


For objects / sprites etc. you could write a function like this

When giving this a range like 1 through 131070 it would perhaps take a while, but still it's much better than restarting the program. Then just go back to the beginning of your code, right after the declarations.
(The removal function of course expects that you don't (like me ':b) store objects / other things in chunks like grass objects start at 100 000, decals at 150 000 and so on, or you'd have to loop through a great many instances).

"I kören hörs de brummande busarna Björnligan och Gondolen"
AndrewT
17
Years of Service
User Offline
Joined: 11th Feb 2007
Location: MI, USA
Posted: 18th Oct 2008 19:36 Edited at: 18th Oct 2008 19:37
This is one problem I commonly run into, and unless you wanna go through all your code then there isn't much of a solution. Really from now on you should design your projects from day one knowing that you'll have to have a way to easily reset everything. If you make a function called InitSprites(), make sure you have a function called UnInitSprites(), that way you can re-initialize every part of your game with a set of functions. At least that's what I do, I'm sure there are other ways.

<<---------CLICK IT
Deego
16
Years of Service
User Offline
Joined: 21st May 2008
Location:
Posted: 19th Oct 2008 01:40
At this point, I think a second program running in the background that executes the game exe on an action is the best solution. I stored my objects in chunks too C:

With my next program I'll definitely keep track of everything. Thanks!
Timber Wolf
20
Years of Service
User Offline
Joined: 2nd Jun 2004
Location:
Posted: 19th Oct 2008 05:32 Edited at: 19th Oct 2008 05:32
I suggest what Rudolpho said and placing a label at the very begining of the code, then performing a GOTO to that label after you delete what needs deleting.



If you do something like that and place the GOTO label before any of the variables are declared then they'll all be set to their original values, while the for/next loop deletes anything you wanted to unload. Unless you really need to delete all the images, you can leave them in the memory for faster sprite creation on the second run.

I use just this system to call the main menu in my RTS. I delete all the sprites used in the User Interface and reuse those values for the sprites in the menu. It's also helpful for commands such as "New Game".


Dabbler
17
Years of Service
User Offline
Joined: 3rd Mar 2007
Location: Minnesota
Posted: 19th Oct 2008 18:14
Hmmm, didn't learn from past projects?

http://forum.thegamecreators.com/?m=forum_view&t=130450&b=1

I suggest reading Steve Vink's Space Invader tutorials, issues 45, 46 and 47 of TheGameCreators Newsletter. I hope they will help you in your future projects.


Whatever...
Ed222
17
Years of Service
User Offline
Joined: 3rd Nov 2007
Location: Calgary
Posted: 20th Oct 2008 02:22 Edited at: 20th Oct 2008 02:23
You could just re-execute the same program automaticlly from the already running program by going

there's no need for a second program.

Login to post a reply

Server time is: 2024-11-25 16:29:23
Your offset time is: 2024-11-25 16:29:23