Behavior accessing a plugin?

For developers using the Construct 2 Javascript SDK

Post » Tue Apr 03, 2012 9:49 am

@Ashley or whoever

Is it possible to have a single plugin with some data/methods then have a separate behavior that can access this plugin data/methods?

If it is possible what would be the best/simplest way of access?

This would be very similar to the Solid behavior actually but I haven't had a good dig around that yet.

Thanks for your time,

Rez
B
21
S
7
G
2
Posts: 185
Reputation: 3,280

Post » Tue Apr 03, 2012 9:59 am

I noticed this post mentions access. I'll have a further look later.
B
21
S
7
G
2
Posts: 185
Reputation: 3,280

Post » Tue Apr 03, 2012 10:15 am

@00Rez

Plugin can access other plugins, behavior can access a plugin, too.

Worksheet plugin connects to a Timeline object in an action to get reference. So that worksheet object can call timeline's CreateTimer function.

Timer behavior is similar with worksheet, it connects to a timeline object, accesses timeline's function..

There are some other way to get the object(plugin) reference. Like -
a. Define a global function reference
b. Then get function reference



It's very interesting to design co-work plugins.
rexrainbow2012-04-03 10:24:44
B
97
S
22
G
177
Posts: 4,113
Reputation: 103,531

Post » Tue Apr 03, 2012 10:39 am

@rexrainbow

I remembered you had some plugins that did this, thought I'd throw this out there before delving deeper.

Your plugins/behaviors are massively useful Rex! Thanks for your time and effort.
B
21
S
7
G
2
Posts: 185
Reputation: 3,280

Post » Tue Apr 03, 2012 10:53 am

@rexrainbow

Using your first method would this allow dynamic access? As the data is changed in the plugin would it also update in the behavior? Sorry if this is a simple question!
B
21
S
7
G
2
Posts: 185
Reputation: 3,280

Post » Tue Apr 03, 2012 10:58 am

@00Rez

A number/text is a value, so these value will not be updated automatically.

A array/object is a (object) reference, so these variable will be updated automatically. (Except you get a clone one.)
rexrainbow2012-04-03 11:03:18
B
97
S
22
G
177
Posts: 4,113
Reputation: 103,531

Post » Tue Apr 03, 2012 11:22 am

@00Rez

It can do code reuse by accessing to other plugin. There is a timer api which can help other plugin maker (include me) to get timer/access timeline.
B
97
S
22
G
177
Posts: 4,113
Reputation: 103,531

Post » Tue Apr 03, 2012 12:08 pm

@rexrainbow

Thanks rex! Your timeline method worked a treat. The plugin is a super fast path finding plugin that uses "pathfinder" behaviors. The original path finding algorithm is MIT License not my own code but the interesting part is someone added bit vectors and arrays to optimise it increasing speed *substantially*. Not sure who this person is though... Still MIT license so will upload eventually.
B
21
S
7
G
2
Posts: 185
Reputation: 3,280

Post » Thu Jun 07, 2012 10:30 am

This is a method to call plugin's action from behavior, so that behavior could extend plugin by calling plugin's action.
[code]cr.plugins_.Text.prototype.acts.SetText.apply(this.inst, [param]);[/code]

This could call other behavior's action. It's also useful, too.
[code]cr.behaviors.Physics.prototype.acts.ApplyForceToward.apply(this.physics_behavior_inst, [f, px, py, 0]);[/code]rexrainbow2012-06-08 06:32:59
B
97
S
22
G
177
Posts: 4,113
Reputation: 103,531

Post » Sun Jun 10, 2012 6:42 pm

[QUOTE=rexrainbow] This is a method to call plugin's action from behavior, so that behavior could extend plugin by calling plugin's action.
[code]cr.plugins_.Text.prototype.acts.SetText.apply(this.inst, [param]);[/code]

This could call other behavior's action. It's also useful, too.
[code]cr.behaviors.Physics.prototype.acts.ApplyForceToward.apply(this.physics_behavior_inst, [f, px, py, 0]);[/code][/QUOTE]

Nice! Thanks Rex. Unless you've already updated the function plugin could you have it so if you try and run a string that isn't set as a function it doesn't throw an error saying the function doesn't exist? Would ignoring be better than throwing an error? Anyway thanks for the contribution. I'm using it for an event system.
B
21
S
7
G
2
Posts: 185
Reputation: 3,280

Next

Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 0 guests