How to Customize Construct 2 Code

Looking to build a team or have a job to offer?

Post » Sat Jan 04, 2014 4:56 am

Hi Everyone, I Need Help in customizing Construct-2 Exported Code.

I made a game for client, He wants to call a function in Index.html to give alert of total-points when user clicks a Specific Button ("Done Button" in Game)

Here is Game Link ....
dl.dropboxusercontent.com/u/196969557/Betty_Bellows%20V2.5/index.html
Right Now When you click on Done, it calls browser alert message.

But My Client wants to Implement this in Index.html.
I Need help how I can call this function in Index.html when user clicks on done button, & Access ("TotalPoints" Global Variable in C2Project)
/**** (I Have less Knowledge about Coding)

index.html
<script>
function update_points(points)
{
alert(points);
}
</script> ***/
B
5
G
1
Posts: 9
Reputation: 422

Post » Tue Jan 07, 2014 2:09 am

The Browser object has an alert action already.
B
47
S
14
G
7
Posts: 603
Reputation: 8,141

Post » Tue Jan 07, 2014 6:56 am

I know that Browser has a alert action. But When I export it, Browser alert can not be accessed due to C2-Export Mechanism. My Client wants to call API in this function. I See nothing in "runtime File" which can be understood.
B
5
G
1
Posts: 9
Reputation: 422

Post » Tue Jan 07, 2014 8:50 am

If I understand this correctly, using the execute javascript action of the browser object should do the trick. Have you tried that already?
B
23
S
6
G
11
Posts: 1,045
Reputation: 8,061

Post » Tue Jan 07, 2014 9:20 pm


c2runtime.js
at the very top or bottom(before or after C2 closure) insert the API code chunk. Make sure it's part of the window.[foo name space]

then in C2
Browser.execJS( api.function_name )


You will need to insert this custom JS code into the c2runtime every time.
B
90
S
18
G
9
Posts: 2,455
Reputation: 15,038

Post » Wed Jan 08, 2014 1:17 pm

[QUOTE=jayderyu]
c2runtime.js
at the very top or bottom(before or after C2 closure) insert the API code chunk. Make sure it's part of the window.[foo name space]

then in C2
Browser.execJS( api.function_name )


You will need to insert this custom JS code into the c2runtime every time.
[/QUOTE]

Any particular reason why you suggest to put the code in the runtime file?

Having it in the index.html should work just as well. Also you simply could keep a separate index file in the export folder without the need to always inject the script anew after exporting.
B
23
S
6
G
11
Posts: 1,045
Reputation: 8,061

Post » Wed Jan 08, 2014 4:10 pm

You can also create a simple plugin with no functions. Which sole job is to insert the custom api into window.foo name space. Then he wouldn't even need to modify anything else. So why not that. Even makes it easier in the long run. Also some wrappers don't even use the index.html.

I can't say he is using CJS, more than likely it's just for a web browser. But if say it were CJS. Then putting the modifcation in index.html would have no effect as index.html isn't being used.jayderyu2014-01-08 16:12:15
B
90
S
18
G
9
Posts: 2,455
Reputation: 15,038

Post » Wed Jan 08, 2014 8:06 pm

[QUOTE=jayderyu] You can also create a simple plugin with no functions. Which sole job is to insert the custom api into window.foo name space. Then he wouldn't even need to modify anything else. So why not that. Even makes it easier in the long run. Also some wrappers don't even use the index.html.

I can't say he is using CJS, more than likely it's just for a web browser. But if say it were CJS. Then putting the modifcation in index.html would have no effect as index.html isn't being used.[/QUOTE]

Ah, I see where you're coming from. I suppose you could also easily include an external js script by adding the CallJS plugin, which has a property to do so.
B
23
S
6
G
11
Posts: 1,045
Reputation: 8,061

Post » Wed Jan 08, 2014 11:48 pm

Executing strings with the Browser object is an ugly hack. If you want to do it properly, use the Javascript SDK.
Scirra Founder
B
399
S
236
G
89
Posts: 24,519
Reputation: 195,361

Post » Thu Jan 09, 2014 8:30 am

[QUOTE=Ashley] Executing strings with the Browser object is an ugly hack. If you want to do it properly, use the Javascript SDK.[/QUOTE]

Can't say I'm that much into cosmetics. So I wouldn't really care if something was "ugly", as long as it worked of course.

But seriously it seems to me that making a plugin just to use one javascript method or two is a little bit of an overkill.

Would you care to elaborate briefly why you deem it a bad idea to use the execute javascript action/ expression of the browser object? Are there possible issues people don't usually consider?
B
23
S
6
G
11
Posts: 1,045
Reputation: 8,061

Next

Return to Job Offers and Team Requests

Who is online

Users browsing this forum: No registered users and 3 guests