How to get data from construct to html page

Get help using Construct 2

Post » Wed Jan 29, 2014 7:00 am

Hello , first of all thank you for this wonderful software.

My question is , how can i get data from C2 to html page , i want to display for example health,golden data in html page.

is there a way to display directly from construct with javascript?

For example :

[CODE]var goldenfromC2 = document.getElementById('golden');
document.getElementById('goldenhtml').innerHTML= goldenfromC2.value;[/CODE]


sorry for my english , i hope you understand me .. have a nice dayThailan132014-01-29 08:01:37
B
3
Posts: 3
Reputation: 181

Post » Wed Jan 29, 2014 8:11 am

Hey !

Welcome to C2 for a start ^^

About your problem, don't forget C2 runs on javascript, and it will be the way to communicate with the webpage that hosts it. Specificaly, if you add the Browser object, you can use its expression "Execute javascript", that will execute the code you want. This is the way to send anything you like from your game to your webpage.
B
17
S
8
G
4
Posts: 461
Reputation: 6,157

Post » Wed Jan 29, 2014 8:29 am

Thank you for answer ,

for example i have a global variable called `money` how can i send this data to my webpage can you give me an example please?

i did , "alert(this.runtime.all_global_vars);" but it returned me
[object, Object]

i need display these global variables as text on my webpage not as text object on canvas
because i want to make Ui on html page.Thailan132014-01-29 08:35:36
B
3
Posts: 3
Reputation: 181

Post » Wed Jan 29, 2014 8:45 am

No, directly in C2, create an event going like this :

System:Every Tick
-- Browser : execute Javascript("var money_outside_C2 = "&money)

This will eval the string you build in the Execute javascript parameter. Here, I declared a variable in the page context (window.money_outside_C2), that you can access through the webpage as you wish, and that is updated every tick.
It would be better to do this not every tick, but when the money change of course. Also, you could execute something like "myClassWrittenInJavascript.update_money("&money&")", to trigger a custom function you made outside of C2.

EDIT : ho, and if you had logged the globals instead of alerting it, you would have seen that you can access those by hand too, no need to eval in C2.Guizmus2014-01-29 08:47:24
B
17
S
8
G
4
Posts: 461
Reputation: 6,157

Post » Wed Jan 29, 2014 9:24 am

I did like so ,

C2:
Execute Javascript("var money_outside_C2 = "&money)

Index.html:
document.getElementById('moneydiv').innerHTML=window.money_outside_C2;

it says money_outside_C2 is not defined

sorry , i dont know javascript too much..
B
3
Posts: 3
Reputation: 181

Post » Wed Jan 29, 2014 6:58 pm

The best tip here is that if you want to do game development with HTML5 and you want to do things outside the canvas, learn javaScript. Just saying, as a game developer, you are going to have to put in some effort to learn the technology that you are using.
B
49
S
12
G
10
Posts: 1,833
Reputation: 14,583


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 26 guests