[SOLVED] make an array without knowing the required size?

0 favourites
  • 4 posts
From the Asset Store
In this template the music plays without looping in your game
  • I want to load data into an array but the amount of data depends on the mysql database and that amount of data can grow and shrink.

    I am placing little flags on a city map and have 4 bits of data coming in per flag. (id, color, x-coordinate and y-coordinate)

    The number of flags will change constantly though because users can add and remove them.

    So every time the map loads it gets the current flags (4 bits of data each) from the mysql database.

    I want to have a 2 dimentional array to load the data into and use a row per flag. So position 1.0, 1.1, 1.2 and 1.3 are the first flag.

    Then 2.0, 2.1, 2.2, and 2.3 for the next etc..

    But I don't know how many flags will be loaded so i cannot beforehand create the array since I don't know the size it has to be yet.

    So is there a way that i can either..

    -Check the number of bits of data that come in through AJAX.LastData (divided by a separator). And then quickly create the array in the right size and load the data into the array?

    OR

    -Create a 4x1 array and increase the Y size of the array on the fly while loading data into it?

    • Check the number of bits of data that come in through AJAX.LastData (divided by a separator). And then quickly create the array in the right size and load the data into the array?

    This would be pretty easy using TokenCount

    tokencount(src, separator)

    Count how many tokens occur in src using separator. For example, tokencount("apples|oranges|bananas", "|") returns 3.

  • Another way would be to push the desired info into the array..

    Push

    Add a new value either to the beginning (front) or end (back) of an axis. Since the Array is a 3D cube of values, technically this inserts a new 2D plane of elements all with the given value. However in 1D arrays this adds a single element, and in 2D arrays it inserts a new row of elements.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Tokencount? Awesome!

    And then I just use the 'set size' and that will solve my problem yeeeeuy

    CHEERS LittleStain

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