Communicate between C2 and html

Get help using Construct 2

Post » Mon Mar 11, 2013 8:00 pm

Hi =)

I'm looking for the proper way to communicate between c2 and my own JS functions in the html file.

I can't find a good c2 JS reference, for instance the cr_setSuspended function is even not documented !

So how do I :
- modify c2 global variables from the html page ?
- call a function defined in the c2 event sheet from the html ? Pass in variables ?
- call a js function from c2 and handle the return value ? Calling Brownser Go to url "javascript:..." cannot get the value returned.

Thank you so much for your help =)
B
3
Posts: 5
Reputation: 285

Post » Mon Mar 11, 2013 8:05 pm

You can use the CallJS plugin to call javascript functions, but I'm not sure how to do the other things.
B
63
S
23
G
17
Posts: 254
Reputation: 14,342

Post » Mon Mar 11, 2013 8:39 pm

thanks ! That will help a lot ! I'm wondering why those basic features are not implemented in C2.

So this plugin can call js from c2.
I will also need the inversed way, calling c2 functions from JS.

If we can grab object with getElementById("myC2TextBox") there should be a way to call c2 functions as well !

thank you for your help ;)z
B
3
Posts: 5
Reputation: 285

Post » Mon Mar 11, 2013 8:48 pm

Does this topic helps ?
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,998
Reputation: 57,791

Post » Tue Mar 12, 2013 8:18 am

yes it helped to understand that textboxes can be accessed by id in the html. But you can't access global variables or functions like that.
B
3
Posts: 5
Reputation: 285

Post » Tue Mar 12, 2013 1:01 pm

What's the use case? I can understand calling functions from a library, but why are you putting your own js in the html? It sounds like whatever functionality you're trying to achieve would be better as a plugin.
Moderator
B
72
S
13
G
11
Posts: 900
Reputation: 11,783

Post » Tue Mar 12, 2013 1:11 pm

Is setting a session web storage variable a option for you? Just check it's content every now and then..
B
15
S
4
G
2
Posts: 16
Reputation: 2,129

Post » Tue Mar 12, 2013 5:05 pm

I'm actually building a lottery like game with an opt-in form that tells if you can play or not. I'm using custom html/css/jquery to setup the form as I can't do this properly in C2. So when the form is submitted, I do some ajax to register the user before he can play. Then I need to call a game function to launch the right layout etc.

I managed to trick this, changing a textbox value inside C2 from my custom JS, and on C2 listening for the textbox value to change :



but this is not a proper way to do this simple thing^^
B
3
Posts: 5
Reputation: 285

Post » Wed Mar 13, 2013 11:32 am

@anthonyk You should really use plugins for this sort of functionality. Have a look at the clay.io plugin for some examples of overlayed form functionality integrated into a plugin.
Moderator
B
72
S
13
G
11
Posts: 900
Reputation: 11,783

Post » Wed Mar 13, 2013 12:11 pm

thank you for the advice ! This plugin sounds really great !

I'll take a look ;)
B
3
Posts: 5
Reputation: 285

Next

Return to How do I....?

Who is online

Users browsing this forum: austinblackbelt, Yahoo [Bot] and 21 guests