Author |
Message |
registration
|
Posted: Wed Jan 06, 2010 1:16 am Post subject: Freeing every single variable/array/function/procedure/imported files/pictures/etc |
|
|
Is there a single command to free every single thing that you initially declare at the start of the program? (e.g., when the game is over, you have an option to play again, but you have to reset the variables to the original values but it's easier to just free every memory location?) |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
DemonWasp
|
Posted: Wed Jan 06, 2010 1:59 am Post subject: RE:Freeing every single variable/array/function/procedure/imported files/pictures/etc |
|
|
In general, you don't need to reset any variables to their original values. You need to close opened IO streams, and should probably Pic.Free() your images, though that's not necessary. Nothing else should be required, and no such command exists. |
|
|
|
|
![](images/spacer.gif) |
Zren
![](http://compsci.ca/v3/uploads/user_avatars/1110053965512db6185954b.png)
|
Posted: Wed Jan 06, 2010 2:18 am Post subject: RE:Freeing every single variable/array/function/procedure/imported files/pictures/etc |
|
|
Technically you program takes up memory, and the solution is to click that cool X then run the program again.
Theorectically, this would work. I'm not sure exactly since I seem to have a non-working compiler. Just compile this program to "test.exe".
Turing: |
var input : string
put "Keep going? [Y/N]"
put " > " ..
get input
if Str.Lower (input ) = "y" then
if not Sys.Exec ("text.exe") then
put "The Sys.Exec call failed"
put "Error: ", Error.LastMsg
end if
end if
|
|
|
|
|
|
![](images/spacer.gif) |
wtd
|
Posted: Wed Jan 06, 2010 4:51 am Post subject: RE:Freeing every single variable/array/function/procedure/imported files/pictures/etc |
|
|
Have your game state represented as an object. For a new game, you then only need to instantiate a new object. |
|
|
|
|
![](images/spacer.gif) |
mirhagk
|
Posted: Wed Jan 06, 2010 7:16 am Post subject: RE:Freeing every single variable/array/function/procedure/imported files/pictures/etc |
|
|
hey Zren so are you saying that at the end of the first game it should call itself again? (make sure that the original copy closes though) |
|
|
|
|
![](images/spacer.gif) |
Zren
![](http://compsci.ca/v3/uploads/user_avatars/1110053965512db6185954b.png)
|
Posted: Wed Jan 06, 2010 1:18 pm Post subject: Re: RE:Freeing every single variable/array/function/procedure/imported files/pictures/etc |
|
|
mirhagk @ Wed Jan 06, 2010 7:16 am wrote: hey Zren so are you saying that at the end of the first game it should call itself again? (make sure that the original copy closes though)
Yes. It's not something that should be used yes, but it solves the question at hand. wtd definitely gave the correct method to program though. |
|
|
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: Wed Jan 06, 2010 1:35 pm Post subject: RE:Freeing every single variable/array/function/procedure/imported files/pictures/etc |
|
|
You COULD, like, write a procedure that resets all variables to the default value and frees all pictures (and it SHOULD know what pictures exist, so freeing them shouldn't be a problem)? And then call that when the game resets? That's what I've always done.
It's important to filter out which variables need resetting and which don't matter. |
|
|
|
|
![](images/spacer.gif) |
|