Comparing value in another script

For developers using the Construct 2 Javascript SDK

Post » Tue Feb 04, 2014 5:51 am

I've been trying for a while now to get the fgl api working in a plugin to use it in games. The new version adds a variable to check if Cross-Promotion is allowed by the host, which I am trying to implement as a condition.

Cnds.prototype.FGLEnabled = function()
{
     return fgl.crossPromotionEnabled;
};

As far as I can tell, this should work. However the event ends up firing whether or not the variable is true.

doing console.log(fgl); shows that the object does have the property 'crossPromotionEnabled' and it's true/false at the correct time. But fgl.crossPromotionEnabled just returns undefined.

I've compared the value in a c2 unrelated script and it works perfectly fine too. It seems to only be in the condition function that it wont work.

Is this an engine limitation, or am I that bad at programming?
B
46
S
14
G
7
Posts: 603
Reputation: 8,096

Post » Tue Feb 04, 2014 11:51 am

Im not too sure on this, but perhaps you need to pass the data along to the function

like this:
Cnds.prototype.FGLEnabled = function(DATA)
{
     return fgl.crossPromotionEnabled;
};



Probably something like:

Cnds.prototype.FGLEnabled = function(fgl)
{
     return fgl.crossPromotionEnabled;
};


Not 100% sure, but its the first that popped to mind.
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,562

Post » Tue Feb 04, 2014 12:12 pm

The most likely thing is you just made a typo and it's accessing a non-existent property, which returns undefined. Alternatively maybe it's not actually a boolean, and returns an object or some status in a string that is not a boolean. It depends on the API. There are hundreds of conditions that look like that in the C2 engine, and they all work correctly, so it must be something to do with the FGL API.
Scirra Founder
B
387
S
230
G
87
Posts: 24,249
Reputation: 192,250

Post » Tue Feb 04, 2014 6:27 pm

Given the documentation, it seems to be a boolean. But where did you declared fgl in your runtime code?
Passionate developer

If my work helped you to make your project, please consider making a donation :)
B
44
S
12
G
14
Posts: 631
Reputation: 10,987

Post » Tue Feb 04, 2014 11:34 pm

@Ashley I've narrowed it down and it doesn't work when minified. This doesn't make much sense though since all I'm doing is referencing a variable in a different unminified file. When minified, fgl is an object, and fgl.crossPromotionEnabled is undefined. When unminified, fgl is the same object but fgl.crossPromotionenabled is a boolean as it should be. Is there any way to fix this?
B
46
S
14
G
7
Posts: 603
Reputation: 8,096

Post » Wed Feb 05, 2014 7:49 am

fgl["crossPromotionEnabled"] ?
Passionate developer

If my work helped you to make your project, please consider making a donation :)
B
44
S
12
G
14
Posts: 631
Reputation: 10,987

Post » Wed Feb 05, 2014 1:17 pm

Scirra Founder
B
387
S
230
G
87
Posts: 24,249
Reputation: 192,250

Post » Wed Feb 05, 2014 2:13 pm

@septeven @Ashley thanks :D Everything is working great now.
B
46
S
14
G
7
Posts: 603
Reputation: 8,096


Return to Javascript SDK

Who is online

Users browsing this forum: norman74 and 0 guests