Family Type Picking Problems

This forum is currently in read-only mode.
From the Asset Store
Change delay, create new lines, "backspace" the text
  • 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):

    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?
  • 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:

    if(objType->IsFamily)
          pRuntime->GetFamilyTypes(objType,...,...)  //read the comments for more info on this function[/code:5daw4gzy]
  • 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:

    +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?
  • > +Pick BlueFamily in vector
    -Destroy Sprite
    [/code:2bops2pj]
    

    this would work no matter what, since family and object picking are separate, so the plugin isn't doing anything

    [quote:2bops2pj]

                if ((*i) == begin)
                {
                      pRuntime->SelectAll((*i)->pType);
                      pRuntime->SelectF((*i), (*i)->pType);
                }
          }
    }
    [/code: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]
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)