SOL - How to associate object of type

  • Ok, I can use some help here in regards to the SOL system.

    I have a player based plugin i'm working on. the player plugin stores profile information and handles other stuff in the background. What I want to do however is associate an object type and instances to a player. And when the plugin triggers an event on the player, the associated objects are re-selected(without an event sheet condition).

    So the idea here is

    [EventSheet]PlayerSprite.CustomVarPlayerID is 1
    -- PlayerPlugin.AssosiateObject( ObjectType, Player )
    [/code:1yzxfxqy]
    
    ok so now a PlayerSprite is associated and stored in the PlayerPlugin. So when a condition occurs to trigger the PlayerPlugin I would like the event to build the SOL for the associate PlayerSprite
    
    [EventSheet]
    [code:1yzxfxqy]
    PlayerFooCondition
    -- PlayerSprite.DoSomeBehaviourThing
    [/code:1yzxfxqy]
    
    My thought was to get
    [code:1yzxfxqy]
    instanceProto.Acts.AssociateObjectToPlayer(object, id){
      player[id].solType = object;
      player[id].solMod = this.runtime.getCurrentEventStack().solModifiers
    }
    
    instanceProto.Cnds.PlayerDoesFoo( foo )
    {
      player[ cur_id ].solType.pushCopySol(  player[ cur_id ].solMod  );
    }
    [/code:1yzxfxqy]
    [li]All code is psuedo and the actual code does not reflect the above. The above is only the what I'm trying to do.
    
    However this doesn't seem to work. If this direction should work then I'm doing something wrong. I thought about storing the instances. However that has the problem on Layout changes. If the layout changes then I don't want to maintain the links in the Plugin associated object. I would rather the plugin fail finding the objects.
    
    Help getting this to work would be fantastic.
  • Just a note. I have not solved this problem. Simply put. I just want to store the SOL list, and rebuild it later from the SDK.

  • Looking here:

    https://www.scirra.com/manual/29/object-type

    Couldn't you save a copy of sol.instances and sol.select_all to variables and then set the sol later?

  • R0J0hound

    Thanks for responding. I was kinda getting a little desperate on trying to get this to work. Sound simple and I'm going to try this out. However I could use some help on the follow up.

    What would be the best way to make sure I'm not trying to use dead objects when the game changes layout? The Plugin is Global single. Is there away to check if the object is destroyed on a layout change?

  • Ok, i'm still doing something wrong. Just as a quick reference to what I'm doing

    var items = {};
    
    AssociateObject Action
    items.type = type   from object in the action
    items.instances = type.getCurrentSol().instances;
    items.select_all = type.getCurrentSol().select_all;
    
    ReAssociate CND
    items.type.getCurrentSol().instances = items.instances;
    items.type.getCurrentSol().select_all = items.select_all;
    [/code:1vca2k9w]
    
    This is what I'm doing, and this is not working. I'm probably overthinking the problem and i'm being stupid and  missing something critcal.
  • I think you need to copy the list. Your code above just references it. I forget how exactly but a searching for "JavaScript copy array" should give a way. Also when setting the sol you'll probably want to push a copy of the current sol first. I think there's a runtime function for that.

    A useful reference could be to look at the "pick all" condition or maybe even the "pick by uid" condition.

    For verifying the instances still exist:

    One way that would work could be to find each instance in their object type's list of instances.

    Another idea that could be investigated would be If instances somehow were marked as dead. If it wasn't then you'd need to check if the uid was the same. If it wasn't it would be a recycled instance.

    Just some ideas. I'm not near a dev PC to try any out ATM.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I haven't tested this, but it should work:

    // save sol of type to instList
    var sol = type.getCurrentSol();
    var instList = sol.getObjects().slice();  //the slice() function will copy the array
    
    // filter away instances that were deleted
    instList = instList.filter(function(inst, i, arr)
    	{
    		var iid = inst.get_iid();
    		var instances = inst.type.instances;
    		if( iid<instances.length && instances[iid]===inst)
    			return true;
    		else
    			return false;
    	});
    
    // set sol later
    var sol = type.getCurrentSol();
    sol.instances = instList;
    sol.select_all = false;
    obj.applySolToContainer();
    [/code:3lr99elb]
  • R0J0hound

    Thanks a lot. I am now understanding a lot more on SOL instance management than I did before. I got the system to work. Now I just need to finish the features. You R0ck

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