Can you explain conditions a bit more in depth

  • 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

  • Those two conditions are triggers as defined in edittime.js:

    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");

    The following code from runtime.js is what causes "OnOnline" to be triggered:

    window.addEventListener("online", function() {     self.runtime.trigger(cr.plugins_.Browser.prototype.cnds.OnOnline, self);
    });
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • [Snap! R0J0hound got in seconds before me!]

    Have a look at lines 50-59 of the browser runtime - you'll see that these two conditions are triggered by registered event listeners:

    window.addEventListener("online", function() {
      self.runtime.trigger(cr.plugins_.Browser.prototype.cnds.OnOnline, self);
    });
    
  • Ahhhhhhhhhh omg lol that was way to easy. Thanks :)

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