Triggering condition from a website

0 favourites
  • 5 posts
  • Hi,

    I'm trying to create a plugin which enables me to start the game from a button on the website the game is hosted on, and I am a bit lost.

    The condition (OnExternalGameStart) is set up and showing in Construct2. Now I want to be able to call a function on the plugin which in turn triggers the condition.

    Im trying to do this by calling:

    pluginProto.startGame = function()

    {

         console.log("startGame request recieved");

         this.runtime.trigger(cr.plugins_.SessionData.prototype.cnds.OnExternalGameStart, this);

    }

    But when I test the function I get an error message saying:

    TypeError: Cannot call method 'trigger' of undefined

    I've tried changing the "this" to self as suggested in another post, but that didn't solve it either.

    Can anyone tell me what I am doing wrong, or point me in the right direction?

    Plugin code: [Oh I can't post links yet, PM me for a link to the plugin code]

  • Why don't you just put a button(picture) to your website and direct the image to the games URL?

  • Thanks for the reply!

    Because I want to be able to show the splash screen, which contains a gameplay animation of the game, explaining the rules.

    I would like to keep it that way if at all possible, because when I change something in the gameplay or in the graphics, the animation exlplaining the game changes with it.

  • To further clarify, ideally the game is already running, just not started yet. I would like to be able to let the website tell the game to start.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I got it! I looked at how the Browser plugin worked to see what I missed.

    The sollution appears to be using the instanceProto.OnCreate to determine the scope of self. (I am still not entirely sure how this works, but I'll keep learning)

    On top of that I used an event to fire the condition to the likeness of how the Browser plugin handles these kinds of things.

    Below are the relevant functions how they are implemented now:

    instanceProto.onCreate = function()

    {

         var self = this;

         window.addEventListener("startGame", function () {

              self.runtime.trigger(cr.plugins_.SessionData.prototype.cnds.OnExternalGameStart, self);

         });

    }

    pluginProto.startGame = function()

    {

         console.log("startGame request recieved");

         var event = new CustomEvent("startGame");

         window.dispatchEvent(event);

    }

    Cnds.prototype.OnExternalGameStart = function()

    {

         console.log("Trigger called");

         return true;

    }

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