Triggering condition from a website

Get help using Construct 2

Post » Fri Jan 10, 2014 4:12 pm

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]
B
4
S
1
Posts: 6
Reputation: 287

Post » Fri Jan 10, 2014 5:26 pm

Why don't you just put a button(picture) to your website and direct the image to the games URL?
Image
Check out our start-up and configure your own helmet in true 3D.
B
44
S
11
G
11
Posts: 1,154
Reputation: 9,978

Post » Mon Jan 13, 2014 7:56 am

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.
B
4
S
1
Posts: 6
Reputation: 287

Post » Mon Jan 13, 2014 8:02 am

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.
B
4
S
1
Posts: 6
Reputation: 287

Post » Mon Jan 13, 2014 9:24 am

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;
}
B
4
S
1
Posts: 6
Reputation: 287


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 24 guests