User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Visual Basic 4 / 5 / 6 section within the Software Development category of DaniWeb, a massive community of 402,375 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,083 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums
Views: 7118 | Replies: 2
Reply
Join Date: Sep 2006
Posts: 1
Reputation: adaids is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
adaids adaids is offline Offline
Newbie Poster

Whats the code for a reset button..

  #1  
Sep 25th, 2006
Cause im doing a game so i want to reset the game.. what will be the code so that i can reset all the game and make it like if it was just opened?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2004
Location: Lincoln Park, Michigan
Posts: 1,744
Reputation: Comatose is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 107
Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Moderator

Re: Whats the code for a reset button..

  #2  
Sep 25th, 2006
There really isn't one..... without looking at your project, I couldn't tell you. You'll need to reset all your variables, and all your forms objects, but there is no magic quick reset button.
Reply With Quote  
Join Date: Sep 2006
Posts: 31
Reputation: sendoshin is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
sendoshin sendoshin is offline Offline
Light Poster

Re: Whats the code for a reset button..

  #3  
Sep 27th, 2006
Depending on your coding style, there might be a magic reset button after all. But it all depends on how you code your game.

If all of the variables and controls etc. that you need to reset the values of are contained in forms, a full reset is easy. To test my theory, I set up a simple VB project with a single form and a few controls. After making those controls somewhat functional, I created a single module with only one Public Sub - that's it, nothing else - which had only eight lines of code in it. This is called from the form when you click a button labeled "Reset". Last, I created a second form which is only shown during the game reset, and so doesn't need to be a part of the reset itself. It covers the whole screen on load and has a line object bouncing back and forth between the sides of the form while the game form resets. This form is loaded and displayed when the reset is started, then hidden and unloaded when the reset completes, so it doesn't take up any memory when you aren't resetting. Here's the code of the module, complete in it's entire goodness.

Public Sub ResetGame()
        Form1.Hide       ' Hide the game form...
        Load Form2       ' Load the "Resetting" form...
        Form2.Show       ' Show the "Resetting" form...
        Unload Form1     ' Here's where the actual reset takes place.
        Load Form1       ' If you set up your Form_Load correctly, 
                         ' everything should be loaded with default
                         ' values now.
        Form2.Hide       ' Hide the "Resetting" form...
        Unload Form2     ' Unload the "Resetting" form to save memory...
        Form1.Show       ' Show the game form - reset complete!
End Sub

Note that this will only work if all of your game variables are in your game form(s). Any values stored in modules, for example, will still have to be cleared manually.

With that, your Form_Load or Sub Main should have the proper code to initialize every value to a "new game" value anyway, meaning all you have to do is re-run the Sub Main or the Form_Load (whichever one you use to start the game). The only drawback to this is that if you still have code running (such as an unfinished game loop or a function that only got halfway done), it will try to continue running with the "new game" values. The Unload/Load method I showed above should stop those as well.

Either way, the solutions do vary depending on your coding style. These are some options, though, to get you thinking in the right mindset to figure out what you need to do. IF you have any more questions, or if I just confused the hell out of you, feel free to ask!

- Sendoshin
Last edited by sendoshin : Sep 27th, 2006 at 12:37 am. Reason: Comment Layout Cleanup
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Visual Basic 4 / 5 / 6 Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum

All times are GMT -4. The time now is 12:41 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC