How do I bring a json as table on the screen?

0 favourites
  • 5 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • I have a json with an array or keys and values and want to display it as a table. Any suggestion?

    Tagged:

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You want to show something like that on screen?

    What are the values you want to display? Numbers?

  • It would be a table of 20 rows and a mix of columns with strings and numbers

  • You can loop through each elements of the array and create text objects of the right size at the right place like this for example :

    mediafire.com/file/dki6k5iwnyck1gg/TableDisplay.c3p/file

    i'll let you tweek the numbers. You can also add a background to the table, or cell borders, just do it in the loop and set their size just as I set the size of the text objects.

  • Thanks, for the information, You made me thinking into the right direction.

    After a while I decided to script it in javascript instead as an action:

    var json=JSON.parse(runtime.globalVars.ATH_ladder);

    const TextInstance = runtime.objects.ATH_txtResult.getFirstInstance();

    TextInstance.text="";

    var i,j;

    var x=TextInstance.x;

    var y=TextInstance.y;

    var ti;

    var maxlines=TextInstance.height/20;

    var table_1=0, table_2=0, table_3=0;

    for (i=0, j=0;i<maxlines;i++) {

    if (json.ladder.position.length>table_1)

    table_1=json.ladder.position.length;

    if (json.ladder.score.length>table_2)

    table_2=json.ladder.score.length;

    if (json.ladder.displayname.length>table_3)

    table_3=json.ladder.displayname.length;

    }

    ti=runtime.objects.ATH_txtMyResult.getFirstInstance();

    ti.text="This game: " + json.ladder[0].position + " position. Score: " + json.ladder[0].score;

    for (i=1, j=0;i<maxlines;i++) {

    ti=runtime.objects.ATH_txtResult.createInstance(0,x,y+(j*20));

    ti.text=" "+ json.ladder.position;

    ti=runtime.objects.ATH_txtResult.createInstance(0,x+20+(table_1*10),y+(j*20));

    ti.text=" " + json.ladder.score;

    ti=runtime.objects.ATH_txtResult.createInstance(0,x+20+((table_2+table_1) *10),y+(j*20));

    ti.text=" "+ json.ladder.displayname;

    ti=runtime.objects.ATH_txtResult.createInstance(0,x+20+((table_3+table_2+table_1) *10),y+(j*20));

    ti.text=" "+ json.ladder.date;

    j++;

    }

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