Family Type Picking Problems

Forum for plugin, effect and behavior programmers. Please use the Help & Support forum for help using Construct.

Post » Wed Sep 16, 2009 4:02 am

I'm currently having problems with a plugin I'm working on regarding family picking -- or rather, family type comparison. The setup is like this:

I have a CRunObject* vector which I can add objects to through an action. With a condition I've set up, the user can specify an object type. The plugin iterates through the vector to see if any of the objects inside it match the type specified and then picks them. Here's how the code is laid out(non-bracket or comment lines are numbered for easier reference):

[code:35a49waq]
1. vector<CRunObject*> objects;
...

// The type of the object specified in Construct
2. CRunObjType* objType = params[0].GetObjectParam(pRuntime);


// Iterate through the vector and find objects of like type
3. vector<CRunObject*>::iterator i = objects.begin();

4. for ( ; i != objects.end(); i++)
{
5. if ((*i)->pType == objType)
{
6. pRuntime->SelectAll((*i)->pType);
7. pRuntime->SelectF((*i), (*i)->pType);
}
}
[/code:35a49waq]

If the given object type -- objType -- is a specific object, everything works fine. However, if you substitute the specific object for a family, the type check in line 5 always returns false, resulting in no objects being picked.

Is this a problem in the way I'm comparing the types of the two objects?
Moderator
B
98
S
37
G
19
Posts: 1,584
Reputation: 17,817

Post » Wed Sep 16, 2009 7:49 am

pType will always return the specific type of the object

I haven't tried this before, but it looks like you would have to do:
[code:5daw4gzy]
if(objType->IsFamily)
pRuntime->GetFamilyTypes(objType,...,...) //read the comments for more info on this function[/code:5daw4gzy]
Spriter Dev
B
88
S
21
G
12
Posts: 3,240
Reputation: 16,486

Post » Wed Sep 16, 2009 8:58 pm

Well, I managed to come up with a method for bypassing the problem, but I'm having actual picking problems now. I can specify a family as the type and the correct objects will be picked, but only if you're acting upon a specific member type inside the family. For example, if my condition and action setup was like this:

[code:38xv5g5e]
+Pick BlueFamily in vector
-Destroy Blue
[/code:38xv5g5e]
All instances of blue would be destroyed. If I do this, however, specifying a member type of the family but still picking a family:
[code:38xv5g5e]
+Pick BlueFamily in vector
-Destroy Sprite
[/code:38xv5g5e]
The correct objects are picked and destroyed. Here's the code with the changes applied:

[code:38xv5g5e]
vector<CRunObject*> objects;
...

// The type of the object specified in Construct
CRunObjType* objType = params[0].GetObjectParam(pRuntime);
CRunObject** typeInstances;
int count;

pRuntime->GetTypeInstances(objType, typeInstances, count);
CRunObject** end = typeInstances + count;


// Iterate through the vector and find objects of like type
vector<CRunObject*>::iterator i = objects.begin();

for ( ; i != objects.end(); i++)
{
CRunObject** begin = typeInstances;
for ( ; begin != end; begin++)
{
if ((*i) == begin)
{
pRuntime->SelectAll((*i)->pType);
pRuntime->SelectF((*i), (*i)->pType);
}
}
}
[/code:38xv5g5e]
This checks to see if the object currently pointed to by my CRunObject* vector iterator is equal to one of the instances that belongs to the specified family type. Anything I'm doing wrong here?
Moderator
B
98
S
37
G
19
Posts: 1,584
Reputation: 17,817

Post » Wed Sep 16, 2009 9:47 pm

[quote="linkman2004":2bops2pj]
[code:2bops2pj]
+Pick BlueFamily in vector
-Destroy Sprite
[/code:2bops2pj][/quote:2bops2pj]
this would work no matter what, since family and object picking are separate, so the plugin isn't doing anything
[quote:2bops2pj][code:2bops2pj]

if ((*i) == begin)
{
pRuntime->SelectAll((*i)->pType);
pRuntime->SelectF((*i), (*i)->pType);
}
}
}
[/code:2bops2pj][/quote:2bops2pj]
each time you call SelectAll((i*)->pType), if that type was already selected before, you're basically undoing the selection and starting over, so in the end, only the very last of each type that was picked in this manner would be picked

I think you need to use the isFamily and GetFamilyTypes functions
[code:2bops2pj] if(objType->IsFamily)
{
pRuntime->GetFamilyTypes(objType,Types,count) ;
//loop through Types with iterator i;
for (i is less than size of types)
{
getInstances of i;
selectall of i;
for (each instance of i)
{
if (instance is in vector)
select instance;
}
}
}
else
{
pRuntime->SelectAll(objType)
get instances of objType
for (each instance)
{
if (instance is in vector)
select instance;
}
}[/code:2bops2pj]
Spriter Dev
B
88
S
21
G
12
Posts: 3,240
Reputation: 16,486

Post » Fri Sep 18, 2009 3:03 am

Using IsFamily and GetFamilyTypes doesn't seem to work either. I have the same problem using them as usual.

Maybe I could prod David into releasing the source for the pairer plugin. The "For each pair" condition would probably cover what I'm trying to do.
Moderator
B
98
S
37
G
19
Posts: 1,584
Reputation: 17,817


Return to Construct engineering

Who is online

Users browsing this forum: No registered users and 0 guests