Populating a 2D array fully

0 favourites
  • 2 posts
From the Asset Store
you can add, remove and reorder list items and many more
  • Hey, I'm trying to make a random map by populating an array with data and then 'rendering' it with object tiles. So this is what I have:

    <img src="http://img194.imageshack.us/img194/4631/2y3j.png" border="0" /> This is executed at the start of my layout. However, this only populates the first 30 or so indexes, leaving the rest with a value of 0. Leaving me with this:

    <img src="http://img59.imageshack.us/img59/8522/ksff.png" border="0" />

    As you can see, the bottom lines are all the same. What's wrong here?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I'm going to assume your array is 10x10, in which case you need to set genX to 0 when genX equals 9 - the last column in the array.

    However, I don't suggest looping through arrays like this - it's simply messy and convoluted. Standard procedure when looping through a 2D array is to use a nested For loop to go through the rows and columns. Example:

    <img src="http://i.imgur.com/RjwJcnZ.png" border="0" />

    Note that the bounds on For loops are inclusive, so each of these loops will go from 0 to 9 including 0 and 9.

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