Can you explain conditions a bit more in depth

For developers using the Construct 2 Javascript SDK

Post » Tue Feb 12, 2013 5:26 pm

I'm trying to go through current plugins to wrap my mind around how the plugins work and I'm stuck at conditions. I can't seem to wrap my mind around them. Heres an example from the browser plugin:

Cnds.prototype.OnOnline = function()
     {
          return true;
     };
     
     Cnds.prototype.OnOffline = function()
     {
          return true;
     };
How does it know without some sort of conditional statement that the browser switched from online to offline? It seems from the look of it they will both always be true when referenced. What am I missing? Thanks in advance,

Lance
B
68
S
21
G
15
Posts: 701
Reputation: 15,604

Post » Tue Feb 12, 2013 6:06 pm

Those two conditions are triggers as defined in edittime.js:
[code]AddCondition(3, cf_trigger, "On went online", "Browser", "On went online", "Triggered when user is offline and a connection becomes available.", "OnOnline");
AddCondition(4, cf_trigger, "On went offline", "Browser", "On went offline", "Triggered when user is online and the connection becomes unavailable.", "OnOffline");[/code]

The following code from runtime.js is what causes "OnOnline" to be triggered:
[code]window.addEventListener("online", function() {     self.runtime.trigger(cr.plugins_.Browser.prototype.cnds.OnOnline, self);
});[/code]
B
79
S
24
G
54
Posts: 4,746
Reputation: 40,755

Post » Tue Feb 12, 2013 6:13 pm

[Snap! R0J0hound got in seconds before me!]
@lanceal
Have a look at lines 50-59 of the browser runtime - you'll see that these two conditions are triggered by registered event listeners:
[CODE]window.addEventListener("online", function() {
self.runtime.trigger(cr.plugins_.Browser.prototype.cnds.OnOnline, self);
});
[/CODE]Velojet2013-02-12 18:16:51
B
105
S
20
G
12
Posts: 549
Reputation: 20,320

Post » Tue Feb 12, 2013 6:22 pm

Ahhhhhhhhhh omg lol that was way to easy. Thanks :)
B
68
S
21
G
15
Posts: 701
Reputation: 15,604


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 0 guests