how to access commonActs from a behavior?

0 favourites
  • 13 posts
From the Asset Store
Skin it
$20 USD
A skin plugin and behavior to add a skin system in your game.
  • 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.

  • 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.

  • 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.

  • c2plugins.blogspot.tw/2014/02/reuse-ace.html

    can you explain what this is? not sure what it is about.

  • "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()

  • "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.

  • 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);

  • 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).

  • 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?

  • Thanks for that tip!

    Okay, seems like it might be choosing the first instance of the objectType..

    I believe by calling the ZMoveToObject it was expecting to be run in an event which would have a SOL..

    var other = obj_.getFirstPicked(this);

    is in the call, so I think it tried to pick from SOL.. so in this case it would always pick the first instance of the object apparently.

    I went and copied the code into my behavior and replaced that so that it doesn't try to pick anything(since the behavior already has the object picked), and now it works..

    So I guess I'll live with this unless anyone knows how to change the SOL??

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • From the sdk manual you can get the SOL:

    https://www.scirra.com/manual/29/object-type

    so you can get the current SOL with:

    var sol = obj_.getCurrentSol();

    The docs say to not modify other object's sol but I guess you could modify it, call that action, and then change the sol back to what it was.

    //save current
    var old_instances = sol.instances;
    var old_select_all = sol.select_all;
    
    // set new
    sol.instances = [this.pinObject];
    sol.select_all = false;
    
    // call action here
    
    //restore old
    sol.instances = old_instances;
    sol.select_all = old_select_all;[/code:3vdezqca]
  • nice, thanks for the info! That works great!

    I feel like I've gained some new brain cells and can make better plugins/behaviors now.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)