Repsajo's Forum Posts

  • 3 posts
  • I'm having some trouble getting this.something to reference what I want it to reference. I've read through this to help me:

    quirksmode.org/js/this.html

    My problem is that when I try to call this.runtime.trigger in certain locations in my code, it tells me that it can't call method trigger of undefined. So this.runtime obviously isn't pointing where I want it to point.

    Here's what I have:

    instanceProto.onCreate initiates a websocket. When that socket receives a message, I want it to store data from the message in an object that my conditions and expressions will be able to see. Originally I had this:

    instanceProto.onCreate = function() {

        //Other stuff

        var socket = new WebSocket(//My server's address

        //socket stuff

        socket.onmessage = function(evt) {

            this.data = evt.data;

        }

    }

    That wouldn't work, presumably because the 'this.' in 'this.data' refers to 'socket'. In order for my expressions to be able to reference the data as this.data, this would need to refer to... instanceProto? Say I want the following operation to work:

    cnds.thisIsACondition = function(indexOfWantedData) {

         if(this.data[indexOfWantedData] > 17) {

              return true;

         }

         return false;

    }

    I've gotten the conditions to read from the data object correctly using this setup:

    instanceProto.onCreate = function() {

        //Stuff

        socket.onmessage = function(evt) {

            instanceProto.updateData(evt.data);

        }

        //stuff

    }

    instanceProto.updateData = function(data) {

        this.data = data;

    }

    So this works. Marvelous! My conditions will read this correctly. Then I tried adding in the triggers, changing the last function to this:

    instanceProto.updateData = function(data) {

        this.data = data;

        this.runtime.trigger(cr.plugins_.MyPlugin.prototype.cnds.thisIsATrigger, this);

    }

    And I get errored out, with a "cannot call trigger of 'undefined'" thing.

    (I currently can't get the exact error message since I'm not on the computer I have the work on, but I can post the exact error message later today if necessary)

    So. If anyone knows why this.runtime isn't defined inside a function of instanceProto, despite the fact that this looks just like code I see in, for example, the Mouse plugin's onMouseDown trigger, I would love the help.

  • Yea, I guess that does make this pretty impossible. Is that something that C2 devs have in mind to change sometime? Or are we stuck with that functionality until the end of time?

    Actually, I don't feel like much would need to be changed to get this working. The current limit is that expressions can't return expressions. So let the parent objects be something other than expressions. When the engine is looking for expressions, it usually thinks "everything in the exps object must be an expression function". It could be changed to think "every FUNCTION in the exps object is an expression. every ARRAY in the exps object is a parent thing, so look for functions inside that array!"

    Of course this might just be pointless thinking aloud. I'm relatively new here, so I don't know how much the developers pay attention to feature requests in the forums.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hey everyone. I'm wondering if it is possible to hierarchically nest expressions for a plugin. For instance, say I'm writing a plugin where I want my plugin to have the following expressions:

    XPosition

    YPosition

    XVelocity

    YVelocity

    XAcceleration

    YAcceleration

    In order to make everything more compact and easier to use in the C2 interface, I want to be able to have my plugin only have 3 expressions, Position, Velocity, and Acceleration, and then have each of those had an X and a Y expression.

    While it doesn't matter if this were the case (having 6 expressions isn't that bad), I'm actually working on something where I have 20 things as part of my plugin, all of which have an X, Y, and a Z. I'd really like to avoid defining 60 expressions, because that would really get to cluttered for me and the person using my plugin.

    Ultimately, I'd like it such that if the user is in the expressions panel and double clicks on my plugin name, they're shown the 20 things. They can then double click on that and be shown X, Y, and Z.

  • 3 posts