Creating very large arrays quickly in C3

0 favourites
  • 9 posts
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
  • I'm working on a game that stores a LOT of data on all the different objects. The game is a real estate game and there will be several hundred unique houses, each has an address, value, and 5 different characteristics that all need to be stored in one large array that the game will access. Is there a way to convert a spreadsheet to C3 as a 2 dimensional array?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I would say that you have to to convert the xls or csv or whatever into JSON array format then import the JSON.

    haven't done it myself but looks like there are loads of resources out there to do it.

    Maybe

    convertcsv.com/csv-to-json.htm

    Mayabe

    chrome.google.com/webstore/detail/export-sheet-data/bfdcopkbamihhchdnjghdknibmcnfplk

    Maybe

    blog.pamelafox.org/2013/06/exporting-google-spreadsheet-as-json.html

  • Okay, I ran a very simple test file through the .csv to JSON converter you provided:

    Here is the .csv:

    a1,b1,c1,d1

    a2,b2,c2,d2

    a3,b3,c3,d3

    a4,b4,c4,d4

    I ran it through the converter and got this output:

    [ { "a1": "a2", "b1": "b2", "c1": "c2", "d1": "d2" }, { "a1": "a3", "b1": "b3", "c1": "c3", "d1": "d3" }, { "a1": "a4", "b1": "b4", "c1": "c4", "d1": "d4" } ]

    Now if I save this data in a .JSON file and use the JSON plugin to open it in Construct3, will it become a regular array with regular indices?

  • Not just like this.

    As indicated in the manual - construct.net/en/make-games/manuals/construct-3/plugin-reference/json - there is need for keys names.

    Also arrays in Construct go under a specific format :

    {"c2array":true,"size":[10,1,1],"data":[[[0]],[[0]],[[0]],[[0]],[[0]],[[0]],[[0]],[[0]],[[0]],[[0]]]}

    This is a blank 10,0,0 array in Construct. It is an object named "c2array" with a "size" and "data" keys/parameters.

    Your provided string does not even contain a key name and put as is in the JSON object will just trigger an error on parsing.

  • You can use Google's spreadsheet and then copy and paste it to your array json file in C3's array editor.

  • Can you explain how the C3 array editor works?

  • Not just like this.

    As indicated in the manual - construct.net/en/make-games/manuals/construct-3/plugin-reference/json - there is need for keys names.

    Also arrays in Construct go under a specific format :

    {"c2array":true,"size":[10,1,1],"data":[[[0]],[[0]],[[0]],[[0]],[[0]],[[0]],[[0]],[[0]],[[0]],[[0]]]}

    This is a blank 10,0,0 array in Construct. It is an object named "c2array" with a "size" and "data" keys/parameters.

    Your provided string does not even contain a key name and put as is in the JSON object will just trigger an error on parsing.

    Okay. So how would an array look in that format if it were a 10,5,0 array instead of just a single dimension array?

  • Yea , the construct arrays are 3D, you cant have 10,5,0 , it will have no dimension then.

    needs to be a 10,5,1

    anyway forget about what i said above using the converters i tried a few ways a couldn't do it.

    im sure you can do it but its probably a bit complicated for the likes of us

    why cant you drop all your values in a json array in construct 3 wouldn't that be easier ?

    in the project tree

    under objects

    add ajax object (need this to load arrray later)

    add array object (this allows you to use arrays in the game)

    then at the bottom under files add an "array" file

    this adds an array json to your project but think of this as a separate file to your game that you have to load into the array later.

    if you click on the file you can see it as a spreadsheet

    then you can put all your data into this array , you can even take advantage of the 3d aspect

    then you will have to load this json into an in game array at runtime

    on start of layout

    ajax request the json array

    the on ajax completed load the json array into the game array

    then the game can use it

    sorry the wife is shouting up the stairs at me we are supposed to be going out now better go or there'llbe trouble..

  • Thank you! That answers my question perfectly!

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