| | |
Whats the code for a reset button..
![]() |
•
•
Join Date: Sep 2006
Posts: 36
Reputation:
Solved Threads: 1
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.
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
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.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
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
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 1:37 am. Reason: Comment Layout Cleanup
![]() |
Similar Threads
- examples of code for option button (Visual Basic 4 / 5 / 6)
- whats wrong with my code? (JavaScript / DHTML / AJAX)
- Problem with my code. (VB.NET)
- New badges (Geeks' Lounge)
- Hello Everyone, I need Help with my C++ Code... (C++)
- java price is right game help (Java)
- build java game (Java)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: I NEED HELP! -- How to incorporate an .exe to a vbp?
- Next Thread: books to learn vb ???
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows






