How do I format my .json file of array data?

0 favourites
  • 10 posts
From the Asset Store
Source File, music and art pack for Android Negotiator
  • I'm searching and searching and not finding enough info to make this work. I have an Ajax object that is loading a .json file of array data. In debug, I see the the ajax.lastdata value does contain the json data, however my format must be wrong because when I try to array.load the data, it doesn't parse right.

    Here is what I have in my array json file...

    	"c2array": true,
    	"size": [2,4,0],
    	"data": [
    		["right", 0],
    		["backward", 90],
    		["left", 180],
    		["forward", -90]
    I'm trying make an array with 2 values on the X axis and 4 values on the Y axis and the above is obviously wrong. Can you tell me what's wrong with my format?
    Thanks very, very much for your help 
  • This is 4 values on the x axis and 1 value on the y axis


    It looks like your using the x/z axis'.


  • So I'm wrong in thinking the size attrib is size: [x,y,z] ? Or my array structure is wrong? I've built a lot of JS arrays so I thought I was building this correctly, but clearly I'm not :-/

  • It's a little odd at first, you get used to it. Just leave size's at 1 otherwise your data won't be loaded..

  • I'll give that a try later when I get home. Thank you for your help!

  • No variation of the "size" attrib values works. I can see in the array in the debugger that it doesn't have the 2 columns and 4 rows I'm expecting. It has one row with the letter "r". I have no idea what's happening. I suppose these array JSON structures for C2 are not what you would normally build when hand coding in javascript.

    Can someone post an example JSON file layout, like above that is actually loading and working in C2? Please

  • If that doesn't work, maybe you'd be more comfortable with the json plugin?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • What is wrong with the basic JSON structure in my OP? Are my attribs named correctly? Am I missing any required attrib? Clearly my 2x4 array structure needs some different format that inlcudes the "z" axis. Can someone post the proper JSON for this?

    Thanks a lot for your help

  • Your array loads by swapping the size values. [4,2,1]

    Open the debugger and inspect your arrays or you can dump Array.asJSON to text object


  • Ok, following Noncentz705 advice, I built the array in code, then wrote out the JSON with Array.asJSON. Looking in the debugger, this produces a JSON structure like so...

    	"c2array": true,
    	"size": [2,4,1],
    	"data": [
    Which is visually bizarre. Comparing the above JSON to what the array actually looks like is very confusing. You visualize arrays as a grid with X-axis running horizontally left to right, Y-axis running vertically top to bottom. The above looks nothing like that. 
    Here is the JSON from above with some comments to help...
    	"c2array": true,
    	"size": [2,4,1], // these are array dimensions: x, y, z
    	"data": [ 
    		[ // x-axis value, x = 0
    			["right"],["backward"],["left"],["forward"] // y-axis values 0 - 3
    		[ // x-axis value, x = 1
    			[0],[90],[180],[-90] // y-axis values 0 - 3
    I'm not 100% sure where the z-axis is above?!
    [b]Big thanks to 

    Noncentz705 for getting me over the hump![/b]

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