SimSet confusion.
by Ecliptic · in Torque Game Builder · 01/11/2009 (5:38 pm) · 3 replies
Below I have some code that I modified to fit this discussion so there might be a syntax error in there, it is really to show what I am trying to achieve. I have a function that is ran until all the frames are incremented. At the same time a Number image is created and mounted to the image. I want to now go back and create a function that sets the numbers visibility. For some reason using the class of the object does not work so I tried creating a simSet and adding them to it. Then tried to call the simSet so I could use that name to hide the numbers but the %numbers.getName() returns nothing. Is there a simpler way of doing this? And why is the getName() returning nothing? Shouldn't the simSet be creating multiple instances of this object and assigning it a value or name?
Thanks
Dane
//Create the new images (Animated selections).
%image = new t2dAnimatedSprite()
{
sceneGraph = %this;
config = "ImageConfig";
};
%image.isSelectable = true;
//Create the Numbers for the frames.
$NumberCount = ($NumberCount++);
%numbers = new t2dStaticSprite()
{
sceneGraph = %this;
imageMap = "NumbersConfig";
class = "NumberClass"; // the class that will be associated with the object
layer = 1; // the render layer
size = "20 20"; // the size of the object
frame = $NumberCount;
};
%numbers.Mount(%image);
%NumberSet = new SimSet();
%NumberSet.add(%numbers);
//State the name of the object for later use.
echo("number is in SimSet:" SPC %numbers.getName());Thanks
Dane
#2
%NumberSet would be deleted after the end of the function. It sould be this:
To access a number in the set you would call it like this:
If you are trying to show numbers above an object than this is not the best way. You should use a text object. That way you could update it's value through it's .text variable.
That is basically what you could do.
01/12/2009 (3:43 am)
Assumming that your code is all in a function%NumberSet = new SimSet(); %NumberSet.add(%numbers);
%NumberSet would be deleted after the end of the function. It sould be this:
%this.NumberSet = new SimSet(); %this.NumberSet.add(%numbers);
To access a number in the set you would call it like this:
%newFrame = %this.NumberSet.getObject(%numberOfFrame); %this.mount(%newFrame);
If you are trying to show numbers above an object than this is not the best way. You should use a text object. That way you could update it's value through it's .text variable.
%this.numbers = new t2dTextObject()
{
sceneGraph = %this.sceneGraph;
};
%this.numbers.text = %this.score; //this would be where to put the numbers to show
%this.numbers.mount(%this); That is basically what you could do.
#3
Thanks again,
Dane
01/12/2009 (1:58 pm)
Thanks guys for the input. I will work with this and see how things goes. I did not know you could name an object by placing it inside the () when creating an object. I been digging through the references and trying to make small examples and execute them to learn. I appreciate the help!Thanks again,
Dane
Torque 3D Owner Aun Taraseina
echo("number is in SimSet:" SPC %numbers.getName());Since I don't see you assigning a name to the t2dStaticSprite anywhere. If you really want it to print out a name it should be something like this
%numbers = new t2dStaticSprite(nameMe) { sceneGraph = %this; imageMap = "NumbersConfig"; class = "NumberClass"; // the class that will be associated with the object layer = 1; // the render layer size = "20 20"; // the size of the object frame = $NumberCount; };This code here if added to your original code should print out "nameMe".
The simset doesn't create another instance of the object you are adding to it, it just work like an array or list that helps you to get access easier later on. Like you might want to keep a set of the same objects in a simGroup or simSet to do routine stuff.
You could also change this part of your code if you want to print something useful to the console.
echo("number is in SimSet:" SPC %numbers.frame );Aun