A easier way to make this MASSIVE array.

0 favourites
  • 5 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • So, i'm doing this... kind of rhythm game, and the method i have for it is: the player chooses a song (a Y value, which its name is stored in the cell behind using the Z axis)

    then in the main game, the notes are the X elements in the Y value, every time the player hit a note, a variable will pick the value for the next note at

    (currentNote, currentSong).

    When the song starts, the current note is 0 and the curSong is whatever the player picked, so the first note i need its at(0, curSong)

    The game will use the value to make visible a overlay above the note that the player needs to hit(the value corresponds the instance variable)

    After hitting the note, the currentNote variable will go up to 1, so now the value its at(1, curSong).

    As you may have imagined, the problem is, even though the songs are all small (less than 1 min), it's still a HUGE amount of lines, so, before spending my time in that mess, i need to make sure there's not an easier way.

    PLEASE NOTE THAT: The game will NOT have a time line above showing where the notes will hit.

    Example:

  • You can make it a lot easier to enter all the data by storing it in a json file and then uploading it to an Array object using the AJAX object:

    https://www.dropbox.com/s/z6gbnqa22z7x5 ... .capx?dl=0

    Run this in debug and check the AJAX and Array objects to see how the data loads in.

    The json array file needs the following basic structure for C2 to handle it properly:

    {

    "c2array":true,

    "size":[2,3,4],

    "data":[ [ [0,1,2,3], [4,5,6,7], [8,9,10,11] ],

    [

    [12,13,14,15], [16,17,18,19 ], [20,21,22,23] ]

    ]

    }

    1) Save this text file as *.json and add it to your project by right clicking on the files icon in the Projects bar and selecting "import files".

    2) Add an array object and the AJAX object to your project.

    3) Import your json data into the array object by using the AJAX object:

    On start of layout: AJAX | Request yourArray.json (tag "yourArray")

    AJAX | On "yourArray" completed: Array | Load from JSON string AJAX.LastData

    4) All of your strings should now be in the C2 array.

    You can now work on the array however you want using conditions and actions in C2.

  • btw, I just entered the numbers 0-23 as sample data, of course you would add your song data here - make sure you change the size settings to properly reflect your array size.

  • btw, I just entered the numbers 0-23 as sample data, of course you would add your song data here - make sure you change the size settings to properly reflect your array size.

    WOW! Thanks, it did work, i just had to change the algorithm a bit but i still have some questions:

    For testing, i've set my array size in both json and inside construct to a Y of 5, but in the json file i only wrote 3, and the same for the Z axis, like:

    [ [1,4,2,6], [0,10,8,9,9,8,9,10,0], [1,4,2,6] ],[/code:3p2qvkzv]
    
    When i tested it and the game tried to reach a value at Y 4 and 5, a error pop up appeared but the game work as intended anyway, i just wanna know if errors like these would cause any trouble while playing the built version of the game.
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It might cause problems down the line, best to use a value like -1 for values you want to leave blank, just to keep the array tidy. You can then add a condition along the lines of "if value at array(x,y,z) ? -1 do whatever".

    Btw, you don't need to set the size of the array object, it should automatically resize to the dimensions of the json.

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