SOL - How to associate object of type

For developers using the Construct 2 Javascript SDK

Post » Sat Aug 22, 2015 8:17 pm

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
Code: Select all
[EventSheet]
PlayerSprite.CustomVarPlayerID is 1
-- PlayerPlugin.AssosiateObject( ObjectType, Player )


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: Select all
PlayerFooCondition
-- PlayerSprite.DoSomeBehaviourThing


My thought was to get
Code: Select all
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  );
}

[*]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.
B
90
S
18
G
9
Posts: 2,455
Reputation: 15,013

Post » Tue Aug 25, 2015 2:39 am

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.
B
90
S
18
G
9
Posts: 2,455
Reputation: 15,013

Post » Tue Aug 25, 2015 3:49 am

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?
B
91
S
31
G
103
Posts: 5,235
Reputation: 67,756

Post » Wed Aug 26, 2015 12:14 am

@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?
B
90
S
18
G
9
Posts: 2,455
Reputation: 15,013

Post » Wed Aug 26, 2015 1:22 am

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

Code: Select all
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;


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.
B
90
S
18
G
9
Posts: 2,455
Reputation: 15,013

Post » Wed Aug 26, 2015 2:32 am

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.
B
91
S
31
G
103
Posts: 5,235
Reputation: 67,756

Post » Wed Aug 26, 2015 4:17 pm

I haven't tested this, but it should work:
Code: Select all
// 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();
B
91
S
31
G
103
Posts: 5,235
Reputation: 67,756

Post » Thu Aug 27, 2015 2:19 pm

@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
B
90
S
18
G
9
Posts: 2,455
Reputation: 15,013


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 0 guests