SimObject/SimGroup/SimSet Class functions
by Rodney Rindels - Torqued · in Torque Game Builder · 06/18/2006 (1:36 am) · 9 replies
I'm guessing from my results that you can't implement custom functions for SimSets/SimGroups
for instance:
This yeilds the following results:
This seems odd to me, but I'm guessing its because it just wasn't designed to work like this, or I'm screwing up using the wrong Sim type.
Suggestions? Help? Ideas? Burritos?
-Rod
for instance:
new SimGroup(PlayerItems)
{
totalValue="0";
};
function PlayerItems::addItem(%this,%object)
{
%this.add(%object);
%this.totalValue = %this.totalValue + %object.value;
}
function PlayerItems::removeItem(%this,%object,%boolean)
{
%this.remove(%obj);
%this.totalValue=%this.totalValue - %object.value;
if(%boolean)
{
%object.safeDelete();
}
}
function PlayerItems::getTotalValue(%this)
{
return %this.totalValue;
}This yeilds the following results:
==>echo(PlayerItems.getTotalValue()); <input> (0): Unknown command getTotalValue. Object PlayerItems(2393) SimGroup -> SimSet -> SimObject
This seems odd to me, but I'm guessing its because it just wasn't designed to work like this, or I'm screwing up using the wrong Sim type.
Suggestions? Help? Ideas? Burritos?
-Rod
#2
but of course thats ugly since you woldn't necessarily want to tie this behavior to all the superclass.
I'm thinking this is a bug.
06/18/2006 (12:29 pm)
SimObject doesn't work either , interesting the superclass functions fire function SimSet::getTotalValue(%this)
{
if(%this.totalValue)
{
return %this.totalValue;
} else {
return 0;
}
}but of course thats ugly since you woldn't necessarily want to tie this behavior to all the superclass.
I'm thinking this is a bug.
#3
However, as Rob indicates, there will likely be some knock on effects. GuiControl derives from SimGroup and you may run into problems with that. You almost definately don't want to add it to SimObject, that will have knock on effects for every single object in the engine.
T.
06/21/2006 (1:48 pm)
SimObject does not do the namespace stuff. Only ScriptObject, GuiControl and T2D's objects do. This is not a bug, it's by design. If you really need it on SimSet/SimGroup ... have a look at the code for ScriptObject and add it to SimSet / SimGroup yourself.However, as Rob indicates, there will likely be some knock on effects. GuiControl derives from SimGroup and you may run into problems with that. You almost definately don't want to add it to SimObject, that will have knock on effects for every single object in the engine.
T.
#4
I'm not sure why the namespaces aren't linked, but i'm sure along the way somebody had a good reason. Far be it from me to understand why though. To me its inconsistent behavior from the rest of the TS objects classes.
At this point, I'm just going to implement my own data structure class that has the functionality I need.
Thanks Tom.
06/21/2006 (1:56 pm)
Well I'm aware that I can do anything divergent , but since I didn't have a difinitive answer on the status I wasn't going to go there yet. I'm not sure why the namespaces aren't linked, but i'm sure along the way somebody had a good reason. Far be it from me to understand why though. To me its inconsistent behavior from the rest of the TS objects classes.
At this point, I'm just going to implement my own data structure class that has the functionality I need.
Thanks Tom.
#5
06/25/2006 (4:15 pm)
Why not just create a scriptObject with a simSet on it? That seems like the best solution for you. After all, there's nothing in your examples that implies that you would be changing any of the basic functionality of the simGroup, but just adding variables and extra functionality to it. You can do all that with a scriptObject.
#6
06/25/2006 (4:16 pm)
I do use scriptObjects, the point was it just seemed odd to me that these Sim Types didn't hold the same type of functionality as other Sim Types.. No biggie..
#7
Let me know if this doesn't work for you.
06/25/2006 (4:21 pm)
In case I was vague, here's the original code up top modified per what I was talking about:new ScriptObject(PlayerItems)
{
totalValue="0";
set = new SimSet(); // <- make the set on the script object
};
function PlayerItems::addItem(%this,%object)
{
%this.set.add(%object); // <- and then access it here...
%this.totalValue = %this.totalValue + %object.value;
}
function PlayerItems::removeItem(%this,%object,%boolean)
{
%this.set.remove(%obj); // <- ...and here
%this.totalValue=%this.totalValue - %object.value;
if(%boolean)
{
%object.safeDelete();
}
}
function PlayerItems::getTotalValue(%this)
{
return %this.totalValue;
}Let me know if this doesn't work for you.
#8
It's a SimGroup, with class / superClass
And it's been in stock Torque for ages, but nobody noticed ;)
Doesnt look like there's a ScriptSet, but it would be easy to add one.
T.
06/30/2006 (4:51 pm)
So, completely by accident today, I came across this little thing called ScriptGroup. Guess what it does...It's a SimGroup, with class / superClass
And it's been in stock Torque for ages, but nobody noticed ;)
Doesnt look like there's a ScriptSet, but it would be easy to add one.
T.
#9
ScriptGroup allows ability to define custom functions, its a group, its superclass works.... Muhahahahah
The original example works fine utilizing with ScriptGroup.
! ! Nice Find Tom. ! !
07/01/2006 (10:45 am)
Hum interesting. ScriptGroup allows ability to define custom functions, its a group, its superclass works.... Muhahahahah
The original example works fine utilizing with ScriptGroup.
! ! Nice Find Tom. ! !
Torque 3D Owner Robert Blanchet Jr.
I'm not sure if this is a bug or intended. It may be, that giving SimGroups and SimSets this kind of functionality causes some kind of weird behavior. On that note, be careful of the GUI base classes, as they inherit from SimGroup(I think).