Possible to get plugin id from an instance?

For developers using the Construct 2 Javascript SDK

Post » Thu Apr 25, 2013 3:22 am

Say I pick a random instance (or all with layer.instances[]), is it possible to get the id of the plugin (ex. Sprite) the object type of the instance belongs to?

I know how to get the name of the object type and reference the plugin, but I haven't figure out how to get the name (id) of the plugin.

Is it possible? (without hacking the official code, of course)

Thanks.
B
12
S
3
G
3
Posts: 36
Reputation: 3,048

Post » Thu Apr 25, 2013 1:33 pm

I don't think it's needed in the runtime so it's not stored anywhere. Why do you need it?
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Thu Apr 25, 2013 1:53 pm

Well, I don't really needed as this is for practice, but I was thinking of what if there was a scenario where I loop through the objects and check if the object is a Sprite and if so then apply some actions to it.

Also if I have a function that takes a UID and I want to check what plugin the instance with that UID belongs to.MakubeX2013-04-25 13:58:44
B
12
S
3
G
3
Posts: 36
Reputation: 3,048

Post » Thu Apr 25, 2013 6:13 pm

If you want to check if an object is sprite, use:

inst instanceof cr.plugins_.Sprite.Instance

To prevent that line crashing in projects that don't use the Sprite object, first check cr.plugins_.Sprite is not undefined.
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Thu Apr 25, 2013 10:56 pm

Awesome, thanks!
B
12
S
3
G
3
Posts: 36
Reputation: 3,048

Post » Fri Apr 26, 2013 2:03 am

Just want to clarify for anyone else reading this:
cr.plugins_.Sprite.Instance is not defined, I think Ashley meant cr.plugins_.Sprite.prototype.Instance
B
12
S
3
G
3
Posts: 36
Reputation: 3,048

Post » Fri Apr 26, 2013 12:52 pm

Erm, yep, that's what I meant :)
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544


Return to Javascript SDK

Who is online

Users browsing this forum: Baidu [Spider] and 0 guests