Game Development Community

How do I alter several variables of the same name at once?

by Maxim Eremeev · in Torque Game Builder · 11/02/2011 (1:58 pm) · 2 replies

Let's suppose, that I have several objects of the same class (let's call it "Test"), every one of which has a variable set up, that's called "Var". Is there a way for me to alter all of those variables at once in one line? For example, how do I do something like this:

Var -= 1;

to every variable, called var, that belongs to an object of the Test class? Is it even possible?

#1
11/03/2011 (12:40 pm)
You can't do this in one line. You could try something like:

$TestSet = new SimSet();

function Test::onAdd( %this )
{
  $TestSet.add( %this );
}

function modifyTestVars( %amount )
{
  %cTest = $TestSet.getCount();
  for( %i = 0; %i < %cTest; %i++ )
  {
    %obj = $TestSet.getObject( %i );
    %obj.Var += %amount;
  }
}

modifyTestVars( -1 ); // From your example...
#2
11/04/2011 (3:34 am)
Actually, this seems exactly what I need! Thanks a lot.