Populating a 2D array fully

Get help using Construct 2

Post » Sun Sep 29, 2013 2:03 pm

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:
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:

As you can see, the bottom lines are all the same. What's wrong here?
Nothing goes unanswered!
B
24
S
5
G
1
Posts: 434
Reputation: 3,446

Post » Sun Sep 29, 2013 3:36 pm

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:



Note that the bounds on For loops are inclusive, so each of these loops will go from 0 to 9 including 0 and 9.linkman20042013-09-29 15:38:20
Moderator
B
113
S
41
G
20
Posts: 1,586
Reputation: 19,126


Return to How do I....?

Who is online

Users browsing this forum: dop2000 and 10 guests