Bug in SimGroups?
by Christian Stock · in Torque Game Builder · 02/11/2006 (5:59 pm) · 11 replies
Hi, I have this code:
new SimGroup( TownsGroup )
{
new ScriptObject( : CTown )
{
supply_demand_list = new SimGroup()
{
new ScriptObject()
{
name = "Beer";
demand = 50;
supply = 20;
};
new ScriptObject()
{
name = "Cloth";
demand = 40;
supply = 20;
};
new ScriptObject()
{
name = "Fish";
demand = 40;
supply = 100;
};
};
name = "Bergen";
inhabitants = 4000;
};
};
What happens, is that the last ScriptObject "Fish" isn't added to the SimGroup as one would expect, but instead inits the values of new ScriptObject( : CTown ). If I would have the name=Bergen, inhabitants=4000 in front of the supply_demand_list, it would overwrite these values.
I can fix this with a hack by adding this after the fish entry:
new ScriptObject( : CTown ) // FIXME: bug workaround
{
name = "dummy";
demand = 100;
supply = 100;
};
but this is of course not nice.
Am I doing something wrong or is this indeed a bug?
Cheers,
Christian
new SimGroup( TownsGroup )
{
new ScriptObject( : CTown )
{
supply_demand_list = new SimGroup()
{
new ScriptObject()
{
name = "Beer";
demand = 50;
supply = 20;
};
new ScriptObject()
{
name = "Cloth";
demand = 40;
supply = 20;
};
new ScriptObject()
{
name = "Fish";
demand = 40;
supply = 100;
};
};
name = "Bergen";
inhabitants = 4000;
};
};
What happens, is that the last ScriptObject "Fish" isn't added to the SimGroup as one would expect, but instead inits the values of new ScriptObject( : CTown ). If I would have the name=Bergen, inhabitants=4000 in front of the supply_demand_list, it would overwrite these values.
I can fix this with a hack by adding this after the fish entry:
new ScriptObject( : CTown ) // FIXME: bug workaround
{
name = "dummy";
demand = 100;
supply = 100;
};
but this is of course not nice.
Am I doing something wrong or is this indeed a bug?
Cheers,
Christian
About the author
#2
Christian
02/15/2006 (4:37 pm)
Yes, ignorance. I'm just getting started out with Torque scripting and haven't found a lot of good references as yet. What's the difference between a simset and a simgroup?Christian
#3
02/15/2006 (5:02 pm)
An object can be in only ome SimGroup at a time while they can be in as many simsets as they like. Aside that they are similar, just a nice way to keep object organized.
#4
So, basically if I'm used to C++ containers I just use SimSets and don't worry about SimGroups, right?
Christian
02/15/2006 (6:43 pm)
Great, thanks.So, basically if I'm used to C++ containers I just use SimSets and don't worry about SimGroups, right?
Christian
#5
Say I have a base set of enemy types and I want to put them in a SimSet so that for each new level, I just have to pass parameters such as spawn point, rate of spawn and hit points from a level file.
Is that the purpose of a SimSet?
Thanks, and sorry for hijacking.
- Don
02/15/2006 (6:49 pm)
If it's ok for me to jump in here, I would really appreciate a beginners explanation of SimSets and SimGroups. I've read and re-read TDN, and I just don't get it. Say I have a base set of enemy types and I want to put them in a SimSet so that for each new level, I just have to pass parameters such as spawn point, rate of spawn and hit points from a level file.
Is that the purpose of a SimSet?
Thanks, and sorry for hijacking.
- Don
#6
Now in the code you posted, it looks like you're trying to create a SimGroup as a member field of a ScriptObject. You cannot create objects in this way. You have to create the objects seperately and then set the member field. For example:
Edit: If this is done in a script function, you can actualy skip giving the supply_demand_list a name and just use a local pointer.
02/15/2006 (7:15 pm)
Just to clarify things: You can have SimGroups contained inside of other SimGroups.Now in the code you posted, it looks like you're trying to create a SimGroup as a member field of a ScriptObject. You cannot create objects in this way. You have to create the objects seperately and then set the member field. For example:
new SimGroup( TownsGroup )
{
new SimGroup(supplyAndDemandList)
{
new ScriptObject()
{
name = "Beer";
demand = 50;
supply = 20;
};
new ScriptObject()
{
name = "Cloth";
demand = 40;
supply = 20;
};
new ScriptObject()
{
name = "Fish";
demand = 40;
supply = 100;
};
};
new ScriptObject( CTown )
{
name = "Bergen";
inhabitants = 4000;
supply_demand_list = supplyAndDemandList;
};
};Edit: If this is done in a script function, you can actualy skip giving the supply_demand_list a name and just use a local pointer.
#7
A SimGroup is a SimSet, but has one additional characteristic: any one object can only be in one SimGroup at a time.
Usage is exactly the same, but if you put an object into a new SimGroup, it will be removed from any other SimGroup it may have been in.
You should only use SimGroups if you know that only a SimGroup will do what you want. Your default choice between the two should always be SimSet.
02/15/2006 (8:04 pm)
A SimSet is a container of objects. You can add an object to a SimSet, find an object within a SimSet, iterate over all of the objects in a SimSet, as well as other functions.A SimGroup is a SimSet, but has one additional characteristic: any one object can only be in one SimGroup at a time.
Usage is exactly the same, but if you put an object into a new SimGroup, it will be removed from any other SimGroup it may have been in.
You should only use SimGroups if you know that only a SimGroup will do what you want. Your default choice between the two should always be SimSet.
#8
Funnily enough my way of creating ScripObject members almost worked.
Stephen, thanks. I'll be using SimSets from now on.
Cheers,
Christian
02/15/2006 (8:18 pm)
Josh, thanks, this makes sense. Just to ammend - it's better to move the supplyDemand list outside of the TownsGroup, otherwise these tables get added to the list of towns which doesn't make sense because a) they're not towns and b) they have a different structure/behaviour. I guess the local pointer approach won't work this way.Funnily enough my way of creating ScripObject members almost worked.
Stephen, thanks. I'll be using SimSets from now on.
Cheers,
Christian
#9
When I think of attributes I think of things like: the sprite used, hit points, layer, collison. I.e. the stuff that defines what the object is in the game.
When I think of behaviors I include things like this: I have a wander / pathfinding routine, as well as detecting and attacking that I want to be accessible to any of my enemies I choose throughout the duration of the game.
Attributes will change across levels, but behaviors won't; though both may be modified by parameters passed.
Does that make sense? Is it the sort of scenario the SimSets are meant for?
Thanks,
Don
02/15/2006 (8:28 pm)
I've been pondering this since I posted earlier and decided that maybe another way I can ask the question is this: Is it a way of storing attribute information and / or behavior information? Or, am I trying to use the SimSet for something it's not meant for?When I think of attributes I think of things like: the sprite used, hit points, layer, collison. I.e. the stuff that defines what the object is in the game.
When I think of behaviors I include things like this: I have a wander / pathfinding routine, as well as detecting and attacking that I want to be accessible to any of my enemies I choose throughout the duration of the game.
Attributes will change across levels, but behaviors won't; though both may be modified by parameters passed.
Does that make sense? Is it the sort of scenario the SimSets are meant for?
Thanks,
Don
#10
Think of a SimSet as a bag. You can put things in it, and take things out of it. You can touch every object in the bag, and you can count the number of objects in the bag. In a nutshell, that's all a SimSet is--a container for holding and organizing objects.
Attributes as you describe them are basically just as you describe them--either directly created by you via creating fields, ie:
$myCreature.currentHealth = 25;
$myCreature.currentHealth -= 5;
or by defining their properties via things like datablocks and expected fields for the objects provided for you--things like when you create a player (code from older spacescroller demo):
Behaviours as far as I can tell from how you define them are handled via callback script methods that the engine calls based on events occuring within the simulation. For example:
Does that help a bit?
02/15/2006 (8:41 pm)
Neither of those are tied directly to the use of SimSets actually :)Think of a SimSet as a bag. You can put things in it, and take things out of it. You can touch every object in the bag, and you can count the number of objects in the bag. In a nutshell, that's all a SimSet is--a container for holding and organizing objects.
Attributes as you describe them are basically just as you describe them--either directly created by you via creating fields, ie:
$myCreature.currentHealth = 25;
$myCreature.currentHealth -= 5;
or by defining their properties via things like datablocks and expected fields for the objects provided for you--things like when you create a player (code from older spacescroller demo):
$player = new fxStaticSprite2D() { scenegraph = spaceSceneGraph2D; };
$player.setGroup( 1 );
$player.setLayer( 10 );
$player.setPosition("-35 0");
$player.setSize( "14 7" );Behaviours as far as I can tell from how you define them are handled via callback script methods that the engine calls based on events occuring within the simulation. For example:
function fxSceneObject2D::onCollision( %srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts )
{
// Handle Source Object.
switch$( %srcObj.tag )
{
// Player Hit something.
case "player":
// Upgrade?
if ( %dstObj.tag $= "upgrade" )
{
// Fire Upgrade?
if ( %dstObj.upgradeType == 1 )
{
// Yes, so upgrade fire!
if ( $playerFireType < $playerMaxFireType )
$playerFireType++;
.
.
.
}Does that help a bit?
#11
My push to understand was based on the need to get some good organization in place before our project gets much larger and to make content / level creation easier now that we're starting to be happy with the scripted systems and game mechanics. It was in reading the platformer tutorial that I saw SimSets used and I could *almost* see how it would work for us, but it just wasn't clicking.
Now I know why! =D
Thanks again,
Don
02/15/2006 (9:17 pm)
Yes it does - I was beginning to feel more than a little bit dense due to not being able to make sense of it. =) My push to understand was based on the need to get some good organization in place before our project gets much larger and to make content / level creation easier now that we're starting to be happy with the scripted systems and game mechanics. It was in reading the platformer tutorial that I saw SimSets used and I could *almost* see how it would work for us, but it just wasn't clicking.
Now I know why! =D
Thanks again,
Don
Torque 3D Owner Eric Armstrong
Bloody Tongue Games
Is there a particular reason you are using a group in both cases?