Trigger an event from within a site to a C2 game

Get help using Construct 2

Post » Sat Jun 29, 2013 7:30 pm

Hi community, in need of your assistance.

CONCEPT:

I am working on a series of educational games geared for children of various ages, each game contains multiple spritesheets that contain problems sets with various degree of difficulty. There will be an age selection window in the home page of the site before redirecting the user to any of the games. In practice, i would like for each game to change in difficulty based on the age group selected by the user.


PROBLEM:

If the age selection screen is hosted on a separate page/site, what would be the proper way to communicate with the hosted C2 game or how can i trigger an event from outside the game in order to change the difficulty level or in this case the spritesheet?


If anybody can provide a solution or a simple example .CAPX, i would highly appreciate the assistance and let the community know.

Thank you in advance...Animate2013-06-29 20:19:38
B
106
S
20
G
8
Posts: 155
Reputation: 11,716

Post » Sat Jun 29, 2013 7:44 pm

There is an easy work around using invisible text boxes. Text boxes are actually created by the browser not construct2 yet the fine fellows at COnstruct allowed us to give them an ID which can be accessed by JS. So I used it as a messaging method between the two to control when construct was to be visible and not.

Sorry for not including code, it is all on my work computer.
B
5
Posts: 10
Reputation: 370

Post » Sat Jun 29, 2013 8:19 pm

@maex900, that sounds like a simpler solution!.

When you can, would you be able to provide a breakdown of how you achieved the request through JS or the .CAPX,

I will credit you on this.Animate2013-06-29 20:20:07
B
106
S
20
G
8
Posts: 155
Reputation: 11,716

Post » Sat Jun 29, 2013 8:23 pm

I will try to make a quick example, because I will probably forget if I don't do it immediately.
B
5
Posts: 10
Reputation: 370

Post » Sat Jun 29, 2013 8:36 pm

Type "Go" to trigger.

Example:
https://dl.dropboxusercontent.com/u/7900765/Example%20JS%20Connection/index.html

Added to index.html:
<input type="button" value="Search" onclick="doSomething();" />
     <script>
          doSomething(){
          element = document.getElementById(id);
               element.text = "Go";
          }
     </script>

capx:
https://dl.dropboxusercontent.com/u/7900765/Example%20JS%20Connection/New%20project.caproj
B
5
Posts: 10
Reputation: 370

Post » Sat Jun 29, 2013 8:44 pm

You will find a problem once you get to making connections automatic not triggered, because browsers sometimes hate when there is code executing that wasn't user triggered. I can't remember my solution for that. If you run into that problem, you can hunt message me.

I used this to create a project where we went from flash video to construct game back to flash video. amalgamedia.com maex9002013-06-29 20:48:33
B
5
Posts: 10
Reputation: 370


Return to How do I....?

Who is online

Users browsing this forum: plinkie and 23 guests