DeleteVariables()
by Johnathon · in Torque Game Engine · 11/07/2007 (4:52 pm) · 7 replies
Would anyone like to explain to me why I would need to delete a variable? I saw this over on the TDN and it kind of made me think, and I couldn't think of a situation that I would need to.
$edo = "cool"; echo( $edo ); // Prints cool deleteVariables( "$ed*" ); // Delete all globals starting with $ed echo( $edo ); // Prints "" because $edo was deleted
#2
11/07/2007 (5:24 pm)
So would it be a better practice to delete the variables when they are finished rather than just overwriting the content that the variable is holding?
#3
$quest_timer = "";
and so on.
11/08/2007 (4:01 am)
Well I think it would do the same thing, storing a value of nothing takes up the same ammount of space as deleting it i'd imagine, its just handy if you need to delete a large group instead of writing out 1000 lines of$quest_timer = "";
and so on.
#4
And actually I just looked at the engine code and yes, it would be better to delete your variables. The deleteVariables method does actually delete the structures that hold the information.
11/08/2007 (4:08 am)
Also, think about clearing your preferences before loading new ones. Just delete all $pref then load.And actually I just looked at the engine code and yes, it would be better to delete your variables. The deleteVariables method does actually delete the structures that hold the information.
#5
What about arrays?
Edit: Forgot to ask about memory allocation.
11/08/2007 (1:11 pm)
So if it deletes the structure that holds the information, it will help free memory? I assume with most computers I wouldn't need to worry about deleting minor variables, but I could see clearing out large groups of them like you guys suggested.What about arrays?
$MyArray[50]
deletevariable("$MyArray")would that delete all 50 index's?Edit: Forgot to ask about memory allocation.
Torque Owner Michael Bacon
Default Studio Name
Lets say you setup a complex quest system for your single player game using all sorts of variables which you store in a common format:
$quest_name
$quest_target
$quest_timer
Then your player fails the quest and must start over. However he can choose to start any quest he wants. Rather than fill in your $quest variables by hand (lets pretend we have 1000 of them) we simply delete that group.
It works the same for preferences and any other data that can be stored in script variables.