Convert 2D construct array json to javascript 2D array?

0 favourites
  • 4 posts
From the Asset Store
Casino? money? who knows? but the target is the same!
  • So construct arrays are java script objects with some metadata about the array, i was wondering if any one has come up with an alogirthm to convert that json to a pure Java script array and back? I'm asking so I don't have to reinvent the wheel if its been done before.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I don't have a way currently to get both directions, but my json manager plugin will take a js sub-object and convert it to a c2 array/dictionary.

    https://www.construct.net/make-games/addons/138/json-manager

    Don't know if this will help you or not.

  • Array.asJSON, when parsed as javascript gives a dictionary with an entry with a 3d array. Do you really need to convert it?

    You could build your own array with text from the array before passing it.

    global text arrayText = ""
    every tick
    -- set arrayText to "["
    array: for each x
    -- add array.curvalue&"," to arrayText
    every tick
    -- add "]" to arrayText

    Then just pass arrayText when you call some js.

    You could also build a 1d array from it after passing it, or even just use it directly. I mean say you did:

    browser: execute js "myfunction("&array.asJSON&")"

    then in that function you'd access stuff like this:

    function myfunction(c2array)
    {
    	// access value at x=22
    	c2array.data[22][0][0];
    	// access value at x=3, y=2
    	c2array.data[3][2][0];
    	// access value at x=13, y=66, z=5
    	c2array.data[13][66][5];
    }

    Notice it's always a 3d array.

    If you want to convert the 3d array to a 3d one then just go for it. It's the standard type of thing to do when writing code.

  • thanks!

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