Adding code to a SimGroup
by Ricardo Arango · in Technical Issues · 10/10/2008 (10:47 am) · 4 replies
Hi,
I want to have a set of traffic lights, grouped together, and also have various of these sets.
Now i have thought of using SimGroups to groups them. But, I want to have some code that acts on each one of these groups of traffic lights, and then, it updates each traffic light.
So it would be something like this.
updateAllGroups() {
for each group g
g.updateGroup();
}
updateGroup {
for each trafficLight l
l.updateTrafficLight();
}
Now what I want to do is to have 2 or three types of groups behaviors, and be able to reuse the code on the groups. That is, some groups would have, 3,4,5 traffic lights, with different timings, but there might be 3 or 4 of the same type of groups.
So, is there a way to add some scripts to a SimGroup dynamically (or relate them statically) in the server, so that when they it is created, it 'inherits' some properties and methods? So if I add all those groups to a list at the beginning, I can the just call, simGroup.update(). , or what would be the best way to approach this?
Thanks.
I want to have a set of traffic lights, grouped together, and also have various of these sets.
Now i have thought of using SimGroups to groups them. But, I want to have some code that acts on each one of these groups of traffic lights, and then, it updates each traffic light.
So it would be something like this.
updateAllGroups() {
for each group g
g.updateGroup();
}
updateGroup {
for each trafficLight l
l.updateTrafficLight();
}
Now what I want to do is to have 2 or three types of groups behaviors, and be able to reuse the code on the groups. That is, some groups would have, 3,4,5 traffic lights, with different timings, but there might be 3 or 4 of the same type of groups.
So, is there a way to add some scripts to a SimGroup dynamically (or relate them statically) in the server, so that when they it is created, it 'inherits' some properties and methods? So if I add all those groups to a list at the beginning, I can the just call, simGroup.update(). , or what would be the best way to approach this?
Thanks.
#2
I think that's pretty much it.
But is there a way to create the SimGroups in the mission editor, place the shapes in the group using the editor, and somehow make that group inherit some properties and methods defined in code?
My idea is that I can define something like three types of traffic lights sets, and then be able to create them in the editor as SimGroups, and then, somehow those groups will have methods and classes defined else in the code.
But how do I make a SimGroup, inherit the properties and methods of one the group types. Not the objects in it, but the group to behave as a trafficGroupType1, 2 or 3?
Thanks
10/10/2008 (1:18 pm)
Hi thanks,I think that's pretty much it.
But is there a way to create the SimGroups in the mission editor, place the shapes in the group using the editor, and somehow make that group inherit some properties and methods defined in code?
My idea is that I can define something like three types of traffic lights sets, and then be able to create them in the editor as SimGroups, and then, somehow those groups will have methods and classes defined else in the code.
new ScriptObject(trafficGroup) {
// common properties for all group types
}
// common function for all group types
function trafficGroup::update( %this ) {
}
new ScriptObject(trafficGroupType1) {
parent = "trafficGroup";
// specific properties
}
new ScriptObject(trafficGroupType2) {
parent = "trafficGroup";
// specific properties
}
new ScriptObject(trafficGroupType3) {
parent = "trafficGroup";
// specific properties
}But how do I make a SimGroup, inherit the properties and methods of one the group types. Not the objects in it, but the group to behave as a trafficGroupType1, 2 or 3?
Thanks
#4
};
function cruzeDefault::consultarTabla(%grupo){
}
%cruze = new ScriptObject( ) {
class = "cruzeDefault";
};
10/10/2008 (11:06 pm)
$cruces = new ScriptObject(cruzeDefault){};
function cruzeDefault::consultarTabla(%grupo){
}
%cruze = new ScriptObject( ) {
class = "cruzeDefault";
};
Associate Anthony Rosenbaum
function makegroup(){ %group = new SimGroup(AGroup); return %group; } function addThingToGroup(%thingData, %group){ %thing = new scriptObject(){ data = %thingdata; }; if(isObject(%group)) %group.add(%thing); } function doSomethingToThingsInGroup(%group){ for(%i = 0; %i < %group.getcount(); %i++){ %thing = %group.getObject(%i); if(isObject(%thing)) doSomething(%thing); } } function doSomething(%thing){ echo("do something to object" SPC %thing); }