Help with ACE's

For developers using the Construct 2 Javascript SDK

Post » Mon Jan 20, 2014 5:13 pm

Now I'm having a different problem, this time it's with expressions.

Here's my code:

[code]var theReturnNumber = 0;

Exps.prototype.getThisNumber = function (ret)
{
     MyExternalFunction(function(response)
     {     console.log(response);
          theReturnNumber = response;
     });
          
     ret.set_int(theReturnNumber);
};
[/code]

I call this 2ce in a row in construct, essentially saying
[code]if(theReturnNumber == X)
     Textbox.text = theReturnNumber;
[/code]
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:

[code]this.runtime.trigger(cr.plugins_.Foo.prototype.cnds.Foobar, this);[/code]

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().Robsta2014-01-21 16:23:10
B
11
S
3
G
1
Posts: 98
Reputation: 1,062

Post » Mon Jan 20, 2014 5:56 pm

Did you make the corresponding function for your trigger?

Cnds.prototype.Foobar= function ()
{
    return true;
}
ImageImageImage
B
71
S
22
G
257
Posts: 3,788
Reputation: 142,692

Post » Mon Jan 20, 2014 6:11 pm

yep, it looks like this

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

The function doesn't get called (no console log entry, no actions from returning true).
B
11
S
3
G
1
Posts: 98
Reputation: 1,062

Post » Mon Jan 20, 2014 6:34 pm

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

[code]var myRuntime = null;
var myInstance = null;[/code]

Then in pluginProto.Instance() set the values to

[code]myRuntime = this.runtime;
myInstance = this;[/code]

Then proceed to use these variables where needed.

[code]myRuntime.trigger(cr.plugins_.Foo.prototype.cnds.Foobar, myInstance);[/code]
B
11
S
3
G
1
Posts: 98
Reputation: 1,062

Post » Tue Jan 21, 2014 3:53 pm

Bump for new question.
B
11
S
3
G
1
Posts: 98
Reputation: 1,062

Post » Thu Jan 23, 2014 8:49 pm

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.
B
11
S
3
G
1
Posts: 98
Reputation: 1,062

Post » Thu Jan 23, 2014 9:03 pm

Maybe post what you've got so far. It's always hard debugging pseudo code.
ImageImageImage
B
71
S
22
G
257
Posts: 3,788
Reputation: 142,692

Post » Thu Jan 23, 2014 9:46 pm

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.
B
11
S
3
G
1
Posts: 98
Reputation: 1,062


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 0 guests