How do I call a construct 2 Function from external js?

Get help using Construct 2

Post » Tue Oct 21, 2014 7:40 am

Hey all

I want to create a project which is heavily dependant in external javascript code.
Can I call an event sheet function from external js code?

What about vice versa, calling an external js function from construct and receiving return values, for example?

Thanks! :)
B
18
S
7
G
1
Posts: 160
Reputation: 1,934

Post » Tue Oct 21, 2014 12:26 pm

If it's heavily dependent on some JS integration, I strongly recommend the Javascript SDK. You can write your own plugin to do all the integration and present it to the event system.

For smaller one-liner type things, see 'Javascript integration' in the Function object and the Javascript execution features of the Browser object.
Scirra Founder
B
402
S
238
G
89
Posts: 24,628
Reputation: 196,023

Post » Tue Oct 21, 2014 12:37 pm

Hey Ashley,

I want to work with a 3rd party websocket online engine (smartfoxserver) which has a javascript API, and will shoot events to my custom JS code, and in turn I want the game to act accordingly.
Function and Browser won't be able to achieve this behavior, right? :/
B
18
S
7
G
1
Posts: 160
Reputation: 1,934

Post » Tue Oct 21, 2014 2:40 pm

It would be difficult, why not use the Javascript SDK instead then?
Scirra Founder
B
402
S
238
G
89
Posts: 24,628
Reputation: 196,023

Post » Tue Oct 21, 2014 3:11 pm

I had made a plugin which could run c2 function by a list in Json format
http://c2rexplugins.weebly.com/rex_fncallpkg.html

User could generate this Json string at server.
B
110
S
28
G
280
Posts: 4,487
Reputation: 156,566

Post » Tue Oct 21, 2014 7:48 pm

So, you recommend just creating a plugin that will create the instance of the smartfox client, and listen to all events, and trigger conditions when relevant?
It's a hell of a lot of work, it has like 10 or 15 events, about 20 methods I can think of I could use inside the game, not to mention properties... :(
B
18
S
7
G
1
Posts: 160
Reputation: 1,934

Post » Tue Oct 21, 2014 7:49 pm

rexrainbow, I have to say I couldn't exactly figure out what your extension does or how to use it really... Any chance to simplify it a bit? I'm kinda new to construct 2...
B
18
S
7
G
1
Posts: 160
Reputation: 1,934

Post » Wed Oct 22, 2014 10:05 am

@trueicecold

For example, there has a function named "print", which has 1 parameter.
User could send command string in json format

["print","hello world"]

to client.
Then client could run this command string by this rex_fncallpkg plugin. It will trigger "print" function defined in event sheet.
B
110
S
28
G
280
Posts: 4,487
Reputation: 156,566

Post » Wed Oct 22, 2014 10:11 am

Thanks rex needed that
B
257
S
42
G
15
Posts: 1,991
Reputation: 41,411

Post » Wed Oct 22, 2014 10:23 am

@Lordshiva1948

You are welcome.
Since the function call is transferred to a string, it could be saved in variable or passed to another function call.
B
110
S
28
G
280
Posts: 4,487
Reputation: 156,566

Next

Return to How do I....?

Who is online

Users browsing this forum: dop2000 and 6 guests