Manually add JS Code

Get help using Construct 2

Post » Mon Nov 25, 2013 4:00 pm

I need to manually input some JS code into the c2runtime.cs in order to comply with my customers API.

What is the best way of doing this? The code is a simple function which will be needed when I send some AJAX calls.



Thanks!
B
101
S
32
G
11
Posts: 1,552
Reputation: 21,667

Post » Mon Nov 25, 2013 5:41 pm

To make a function to call later use a "start of layout" with the "execute javascript" action in the browser object. You will have to rewrite the first line of your function like this so you can call it later:
[code]this.getHashFromUrl = function()[/code]
Then you can call it later with another "execute javascript" action like this:
[code]this.getHashFromUrl()[/code]

Be warned that it may not work with a minified export. Also in general it is probably preferred to just make a plugin.R0J0hound2013-11-25 17:43:15
B
92
S
32
G
106
Posts: 5,272
Reputation: 69,455

Post » Mon Nov 25, 2013 9:47 pm

@R0j0hound. Thank you. I haven't looked into making plugins, I might do that first.

Appreciate the help.
B
101
S
32
G
11
Posts: 1,552
Reputation: 21,667

Post » Mon Nov 25, 2013 9:54 pm

You're welcome. On further thought "this" is the only thing that's not minified so it should work with a minified export. You only run into trouble if you try accessing thing that will be minified such as "this.runtime".
B
92
S
32
G
106
Posts: 5,272
Reputation: 69,455

Post » Mon Nov 25, 2013 10:08 pm

Gotcha! Thanks.
B
101
S
32
G
11
Posts: 1,552
Reputation: 21,667

Post » Tue Nov 26, 2013 12:47 pm

I strongly recommend using the Javascript SDK if you need to execute more than a single line of javascript.

BTW looks like the Browser object expressions might be able to do what that javascript code does anyway!Ashley2013-11-26 12:48:08
Scirra Founder
B
395
S
232
G
88
Posts: 24,367
Reputation: 193,744

Post » Tue Nov 26, 2013 1:54 pm

Oh, good point Ashley, I hand't even thought of that.
B
101
S
32
G
11
Posts: 1,552
Reputation: 21,667

Post » Wed Dec 04, 2013 9:21 pm

@R0J0hound

Before I go jumping into the SDK, how do I take my code from above and do what you said? Do I replace all the double quotes with single quotes?

OK, I think the answer is yes as I don't get any errors.

Now the next issue is



Do I use Ajax for this, or should I create functions in code to do these?

I am really hoping this info will come in handy to others that plan on selling their games to publishers. Getting this all work out will make it much easier in the future. :).ArcadEd2013-12-04 21:53:09
B
101
S
32
G
11
Posts: 1,552
Reputation: 21,667

Post » Thu Dec 05, 2013 4:46 pm

Or if anyone else has a clue :)
B
101
S
32
G
11
Posts: 1,552
Reputation: 21,667

Post » Thu Dec 05, 2013 8:51 pm

[quote]OK, I think the answer is yes as I don't get any errors.[/quote]
yep.

[quote]Do I use Ajax for this, or should I create functions in code to do these?[/url]
Whichever you can use to get it to work. I'm not too familiar with ajax calls but it may be simpler to use the plugin if there are edge cases it handles. But again I have a knowledge gap about that that you can probably find alot of resources about with google.
B
92
S
32
G
106
Posts: 5,272
Reputation: 69,455

Next

Return to How do I....?

Who is online

Users browsing this forum: Anonnymitet, SashikLV, unxcellent and 7 guests