Help with ACE's

0 favourites
  • 8 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • Now I'm having a different problem, this time it's with expressions.

    Here's my code:

    var theReturnNumber = 0;
    
    Exps.prototype.getThisNumber = function (ret)
    {
         MyExternalFunction(function(response)
         {     console.log(response);
              theReturnNumber = response;
         });
              
         ret.set_int(theReturnNumber);
    };
    

    I call this 2ce in a row in construct, essentially saying

    if(theReturnNumber == X)
         Textbox.text = theReturnNumber;
    

    except with construct's trigger/event system

    Here's what happens:

    The console log displays the correct number every time I call the expression.

    The first time I call the if/display, it returns 0 to both if it is == X and displaying in the textbox.

    Every time after the first that I call it, it returns the number it should have returned the last time I called it (the number the console log returned last time).

    Here's what I want to happen:

    The expression to return the same number as the console.log returns every time.

    1 extra question:

    Does Construct 2 support an array as a parameter? Or should I make an array by parsing a string parameter? example: "(0, 2, 1, 4)"

    The original problem is solved; problem left below:

    Hello, new developer here and I'm making a plugin to integrate an existing API with Construct 2.

    I figure the most efficant way to make a number of conditions is to make them triggered, but I can't seem to make triggered conditions work, for example, if my plugin had ID: Foo, and I was trying to trigger condition Foobar, I would try:

    this.runtime.trigger(cr.plugins_.Foo.prototype.cnds.Foobar, this);

    but this line of code appears to break when I export (HTML5, minified), and test the program online.

    Some more information:

    I'm working with a pf_singleglobal plugin

    I've tried putting this code in various places in runtime.js, including pluginProto.Type() and instanceProto.onCreate().

  • Did you make the corresponding function for your trigger?

    Cnds.prototype.Foobar= function ()

    {

        return true;

    }

  • yep, it looks like this

    Cnds.prototype.Foobar = function (myparam)
    {
         // Generic comment here
         console.log("Some Text Here");
         return true;
    };
    

    The function doesn't get called (no console log entry, no actions from returning true).

  • aha, I think I solved it.

    What I had to do is follow the kongregate example and declare my own runtime, so

    in function() (the big one that encompasses most of runtime.js)

    declare

    var myRuntime = null;
    var myInstance = null;

    Then in pluginProto.Instance() set the values to

    myRuntime = this.runtime;
    myInstance = this;

    Then proceed to use these variables where needed.

    myRuntime.trigger(cr.plugins_.Foo.prototype.cnds.Foobar, myInstance);
  • Bump for new question.

  • I've been looking into this problem for a bit now, and I'm pretty sure the cause is that javascript isn't waiting for the external function to finish before it executes the code that returns the value to Construct; therefore while I tell it to find out the number to return, then return the number, it actually returns the number, then figures out what number it was supposed to return.

    Now what I need to know is the solution.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Maybe post what you've got so far. It's always hard debugging pseudo code.

  • What appears to be the problem is that I want asynchronous events to be called synchronously, which it appears is impossible, so I made a workaround for it (called the asynchronous event every time the value I want to return can change).

    The plugin and getting it to work on other computers is a little complicated to be posting (or parts there of). But I did find a workaround for this specific instance. Hopefully I won't need to use synchronous events much in the rest of the plugin.

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