How do I send javascript commands to C2 game

Get help using Construct 2

Post » Fri Nov 06, 2015 7:16 am

Hi, I am trying to make a C2 game/simulation and instead of the user interacting with the game using the keyboard or mouse, I would like to send javascript commands to the game to simulate mouse clicks or key presses.

The javascript commands will be sent to the the game to change its behaviour if certain conditions occur on the server.

Is it possible to interact with a C2 game via javascript only and if so, how?
B
4
Posts: 4
Reputation: 208

Post » Fri Nov 06, 2015 1:58 pm

Use the plugin SDK.
Scirra Founder
B
397
S
236
G
88
Posts: 24,392
Reputation: 194,454

Post » Sat Nov 07, 2015 12:05 am

B
4
Posts: 4
Reputation: 208

Post » Sat Nov 07, 2015 12:41 am

That plugin is to load files from a website or from the project's files folder. If you want to run javascript you could use the browser plugin's execJs action, but it just runs some code and it doesn't interact with the rest of c2. The sdk is ideal to do that as Ashley said.
B
92
S
32
G
109
Posts: 5,290
Reputation: 70,991

Post » Sun Nov 08, 2015 2:25 am

Thanks for your replies...

Writing a plugin is a little too advance at the moment.

I have found a solution - pass variables between HTML and C2 using javascript. The variables values will be the commands.

Then I can use TextBox.onTextChange event and Textbox.comparevalue to initiate further actions within the game.

Example is shown here to pass data to and from HTML and C2 (using javascript):
viewtopic.php?t=68747&start=0
B
4
Posts: 4
Reputation: 208

Post » Sun Nov 08, 2015 2:28 am

Further to that, on the server side, I can change html hidden field values (with pseudo commands) and then initiate the javascript functions that pass the hidden field values to C2.
B
4
Posts: 4
Reputation: 208


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo and 23 guests