how to access commonActs from a behavior?

For developers using the Construct 2 Javascript SDK

Post » Wed Apr 05, 2017 12:17 am

I'm making a behavior, and need to know how to call the acts.ZMoveToObject from commonace.js from within my behavior.
sorry if this is a noob question.
B
45
S
21
G
65
Posts: 1,115
Reputation: 38,221

Post » Wed Apr 05, 2017 2:14 am

One way to find it is to was console.log(this); somewhere in your plugin. Then you can open up the developer console and you should be able to click the arrow by "this" and browse the object tree.

But off the top of my head since I was messing with this recently:

this.inst.type.plugin.prototype.acts.zmovetoobject.call(this.inst, ...)

Sorry I neglected the capitalzation, I'm on my phone.
B
92
S
32
G
109
Posts: 5,291
Reputation: 70,993

Post » Wed Apr 05, 2017 4:18 am

B
108
S
26
G
272
Posts: 4,471
Reputation: 152,277

Post » Wed Apr 05, 2017 4:21 am

Thanks r0j0hound, that helps a little.
I seem to have run into another issue..
here is my code

behinstProto.tick2 = function ()
{
if (this.zIndex === 1 && (Math.abs(this.pinObject.zindex-this.inst.zindex)>1 || this.pinObject.layer != this.inst.layer ))
{
this.inst.type.plugin.__proto__.acts.ZMoveToObject(1,this.pinObject.type);
}
};

I end up receiving an error message saying..
uncaught typeerror: cannot read property 'index' of undefined.
line 832, 19 or commonace.js

acts.ZMoveToObject = function (where_, obj_)
{
var isafter = (where_ === 0);

if (!obj_)
return;

var other = obj_.getFirstPicked(this);

if (!other || other.uid === this.uid)
return;

// First move to same layer as other object if different
error here>>> if (this.layer.index !== other.layer.index)
{
this.layer.removeFromInstanceList(this, true);

this.layer = other.layer;
other.layer.appendToInstanceList(this, true);
}

this.layer.moveInstanceAdjacent(this, other, isafter);
this.runtime.redraw = true;
};


not sure how to fix this.. maybe I can't call it?

btw, I'm trying to make a pinned object keep the same layer/zindex as the object it is pinned to.
Last edited by Prominent on Wed Apr 05, 2017 4:24 am, edited 1 time in total.
B
45
S
21
G
65
Posts: 1,115
Reputation: 38,221

Post » Wed Apr 05, 2017 4:23 am

rexrainbow wrote:http://c2plugins.blogspot.tw/2014/02/reuse-ace.html

can you explain what this is? not sure what it is about.
B
45
S
21
G
65
Posts: 1,115
Reputation: 38,221

Post » Wed Apr 05, 2017 6:09 am

"this.inst.type.plugin.__proto__.acts.ZMoveToObject"
is not correct

"cr.plugins_.WebStorage.prototype.acts.StoreLocal.call(webstorage_obj, key, value)" ,
- replace "WebStorage" to your plugin name ("Sprite", maybe)
- replace "StoreLocal" to your function name ("ZMoveToObject", maybe)
- replace 1st parameter to the instance ("this.inst")
- replace other parameters according to your function call interface("1,this.pinObject.type", maybe, I am not sure "this.pinObject.type" is correct or not)

Reference : Function.prototype.call()
B
108
S
26
G
272
Posts: 4,471
Reputation: 152,277

Post » Wed Apr 05, 2017 3:38 pm

rexrainbow wrote:"this.inst.type.plugin.__proto__.acts.ZMoveToObject"
is not correct

"cr.plugins_.WebStorage.prototype.acts.StoreLocal.call(webstorage_obj, key, value)" ,
- replace "WebStorage" to your plugin name ("Sprite", maybe)
- replace "StoreLocal" to your function name ("ZMoveToObject", maybe)
- replace 1st parameter to the instance ("this.inst")
- replace other parameters according to your function call interface("1,this.pinObject.type", maybe, I am not sure "this.pinObject.type" is correct or not)

Reference : Function.prototype.call()


The plugin name could be different depending on which object has the behavior.
So if a 9patch has it, it would be NinePatch. If a sprite has it, then it would be Sprite, I think..
How would I find that out?
I guess I would then do cr.plugins_["objectType"] ?

I tried console.log(this); to search through it, but can't find it anywhere.
B
45
S
21
G
65
Posts: 1,115
Reputation: 38,221

Post » Wed Apr 05, 2017 5:04 pm

You need to use the "call" method to set what "this" is.

So change this line:
this.inst.type.plugin.__proto__.acts.ZMoveToObject(1,this.pinObject.type);
to:
this.inst.type.plugin.__proto__.acts.ZMoveToObject.call(this.inst, 1,this.pinObject.type);
B
92
S
32
G
109
Posts: 5,291
Reputation: 70,993

Post » Wed Apr 05, 2017 5:32 pm

oohh I see. Okay, now it is called, but for some odd reason it isn't moving the object to the correct layer.
..just seems to be setting it 1, when it should be set to 6 (pinObject is on 6, this.inst ends up on 1).
B
45
S
21
G
65
Posts: 1,115
Reputation: 38,221

Post » Wed Apr 05, 2017 5:52 pm

Odd. I'd recommend trying the browser's debugger. Open it and select the sources tab. Clicking on a line number will add a breakpoint. That will cause execution to stop so you can inspect the values of everything, and advance it a line at a time. It might help you see some logic errors?
B
92
S
32
G
109
Posts: 5,291
Reputation: 70,993

Next

Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 1 guest