Game Development Community

Scheduling for a Class

by Rachel P · in Torque Game Builder · 01/17/2012 (11:50 pm) · 4 replies

Hey guys, sorry if this is a stupid question with an easy answer, but I just can't seem to figure out how to use a schedule command that will apply the function to all objects of the same class. I know a normal function is like this:

objName.schedule( time, "Event");

How can I replace the objName so that it can refer to multiple objects of the same class?

I tried className.schedule but of course that didn't work... I also tried naming the object with a variable on the onLevelLoaded function (ie calling all objects of my class $classname), but of course the name/variable is only applied to the first object of the class that is created.

Do I need to create a sim set or something? I'm not very familiar with those but will look into it if that's the answer.

Thanks a lot!
Rachel

#1
01/18/2012 (1:23 am)
EDIT: Ignore this. Thought I found a fix but I didn't!
#2
01/18/2012 (9:45 am)
Yep, group the objects in some kind of container and then iterate through the container and call <objId>.schedule() on each object. A SimSet or SimGroup would work for this.
#3
01/18/2012 (9:37 pm)
Thanks! One more quick question. I'm creating some objects in script via the new t2dAnimatedSprite() code. For example:

$blah = new t2dAnimatedSprite()
{sceneGraph = %this;
layer = 4;
size = "54 54";}

etc. The sprite shows up fine and everything, but how do I give it a name so that I can then reference it for schedule functions? $blah doesn't work, and I tried putting a name after the t2dAnimatedSprite(name) but that doesn't work either. It just can't find the object when it calls the scheduling function. Any idea?

Thanks so much! :)
#4
01/19/2012 (4:49 am)
Well, if you are adding them to a set or group, you should be able to reference entries inside those group.

Something like:

$allAnimations = new Simset();

%display = new t2dAnimatedSprite(){
scenegraph = %scenegraph;
canSaveDynamicFields = "1";
useMouseEvents = "0";
...
};

$allAnimations.add(%display);

Then you can loop on $allAnimations.getObject(%X) to do something to every item in that set. To get the upper bounds (or starting point if your prev'ing through) you can do: %cap = $allAnimations.getCount();