Game Development Community

DeleteVariables and Arrays.

by Yue -Rookie Torque 3D- · in Torque 3D Beginner · 09/25/2013 (12:23 pm) · 8 replies

$Amigos[0] = "John";
DeleteVariables("$Amigos[0]");
echo($Amigos[0]);

I'm creating documentation to put on my website about the collections in Torque 3D. According collections I have understood not really because they are simple variables, now my question is whether they are variables that the code above does not work, and I think that somewhere in that global variable remains and is not deleted.

www.torque3d.tk

About the author

http://www.iris3d.tk -Games Studios- <<I do not speak English: I use the google translator>> My goal as a rookie is knowing Torque 3D


#1
09/25/2013 (12:34 pm)
variables are not stored with [] in the table if I recall correctly, rather it is stored as $Amigos0

[] is an appending operator in TS for a more of a way to create a dynamic variable name on the fly (dunno if that's a good way to put it or not) and not necessary a true "array"
#2
09/25/2013 (12:47 pm)
But then a collection is deleted touches make it single or manually?

Edit: Ok I get it, my English is lousy, I put this in and it works.

DeleteVariables("$Amigos0");
#3
09/25/2013 (12:56 pm)
Now the question if I do this.
DeleteVariables("*");

Deletes all variables, including those with [ ] to simulate collections?
#4
09/25/2013 (1:09 pm)
Here's the whole console function (from source/console/consoleFunctions.cpp at about line 2499):
DefineEngineFunction( deleteVariables, void, ( const char* pattern ),,
   "Undefine all global variables matching the given name @a pattern.n"
   "@param pattern A global variable name pattern.  Must begin with '$'.n"
   "@tsexamplen"
      "// Define a global variable in the "My" namespace.n"
      "$My::Variable = "value";nn"
      "// Undefine all variable in the "My" namespace.n"
      "deleteVariables( "$My::*" );n"
   "@endtsexamplenn"
   "@see strIsMatchExprn"
   "@ingroup Scripting" )
{
   gEvalState.globalVars.deleteVariables( pattern );
}

So really you should use
deleteVariables("$Amigos");

and this should not do anything:
deleteVariables("*"); // does not contain "$"
// and no legal variable name contains "*"
#5
09/25/2013 (1:20 pm)
Ok I have understood the asterisk (*) is to eliminate multiple variables that are under a single name space, right?

DeleteVariables("$Recursos::*");

Edit:

and if the collections or variables are not stuck in name spaces, touches manually delete?, calling them by name?

Or I can use this?

DeleteVariables("$*");
#6
09/25/2013 (1:54 pm)
Actually because FindMatch::isMatch() is used by Dictionary::deleteVariables() then Yue's following code will destroy all global variables:
DeleteVariables("*");
#7
09/25/2013 (2:19 pm)
Which I highly recommend not doing as some $globals are used between the engine and scripting layer :P
#8
09/25/2013 (2:52 pm)
Ooooh - lol - that's what I get for posting while doing seven other things... I should have read that more closely. So yeah, don't deleteVariables("*")....

Perhaps we should catch that and disallow it.