How to get data from construct to html page

0 favourites
  • 6 posts
From the Asset Store
Casino? money? who knows? but the target is the same!
  • 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 :

    var goldenfromC2 = document.getElementById('golden');
    document.getElementById('goldenhtml').innerHTML= goldenfromC2.value;

    sorry for my english <img src="smileys/smiley9.gif" border="0" align="middle" /> , i hope you understand me <img src="smileys/smiley36.gif" border="0" align="middle" /> .. have a nice day

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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.

  • 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..

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)