How do I get the plugin id from a behavior?

For developers using the Construct 2 Javascript SDK

Post » Fri Aug 01, 2014 9:17 pm

I'm writing a behavior that needs to adjust its behavior for different plugins. So I need to be able to check which plugin the behavior is attached to. But type.plugin doesn't seem to have any properties that could be used to identify it. I suspect I'm missing something obvious, but I've been all through the docs and can't find anything.

Does anyone know how to get the plugin id or otherwise identify it?

Thanks. :)
B
8
S
2
Posts: 55
Reputation: 616

Post » Sat Aug 02, 2014 6:24 am

@TrickyWidget

You might check official drag&drop behavior.
B
108
S
26
G
272
Posts: 4,472
Reputation: 152,279

Post » Sun Aug 03, 2014 12:39 am

rexrainbow wrote:You might check official drag&drop behavior.

Thanks for the tip. I went all through that code a few times, but I can't see what it is you're indicating.

I did find a purely JavaScript way to do it:

Code: Select all
if (typeof cr.plugins_.Spritefont2 == "function")
   if (cr.plugins_.Spritefont2.prototype.isPrototypeOf(this.inst.type.plugin))

That works well enough, but it's kind of clunky. I'm hoping there's a C2-specific approach that's more direct. Something like this.inst.type.plugin.id would be a gem.
B
8
S
2
Posts: 55
Reputation: 616

Post » Sun Aug 03, 2014 2:10 am

Code: Select all
   function GetDragDropBehavior(inst)
   {
      var i, len;
      for (i = 0, len = inst.behavior_insts.length; i < len; i++)
      {
         if (inst.behavior_insts[i] instanceof behaviorProto.Instance)
            return inst.behavior_insts[i];
      }
      
      return null;
   };


, the core is
Code: Select all
inst.behavior_insts[i] instanceof behaviorProto.Instance

-> object instanceof type
Sorry for not clearly.
B
108
S
26
G
272
Posts: 4,472
Reputation: 152,279

Post » Sun Aug 03, 2014 5:51 am

To test if there has Cr.plugins.spritefont2, just
Cr.plugins.sprutefont2 != null
B
108
S
26
G
272
Posts: 4,472
Reputation: 152,279


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 1 guest