# Arrays

### » Wed Jun 30, 2010 10:59 pm

Hi Guys.

I've just been playing with procedural generation and arrays. In the past I've never been able to grasp them but Construct has helped me a lot, although I think my below average maths skills may hold me back from what I would like to make. I'm just wondering if it is possible to split an array.

eg 5x5 Array - Just 1 value for simplicityin x1,y1.

10000
00000
00000
00000
00000

then turn it into a 20x20 Array, so x1,y1 is now 4 cells. But I need to keep the value at x1,y1 from the 5x5 Array - and place it in x4y4. And obviously if more values were stored in the 5x5 array they would have to transfer to the 20x20 array too.

0000
0000
0000
0001

Does that make any sense? Basically I want to add more detail to the island below by splitting it into smaller chunks.

Here's a current generated island - with sort of depth added to the sea.

Hope that makes sense to someone. Any help would be fanny-tastic .

**EDIT**

Please translate any help into either "Simpleton" or "Baby Talk" otherwise your great help may go right over my head.

B
46
S
23
G
7
Posts: 459
Reputation: 6,763

### » Thu Jul 01, 2010 1:04 am

The simplest way to have flexible multi-dimensional arrays is using a one-dimensional.
Let's say you have an array of 100. If you now want to use it one-dimensional you access it normally (x1, x2, etc). If you'd want to use it as 10x10, you'd access it with (y - 1) * 10 + x, so that [x5, y5] would equal x(45). If you'd want to use it as 4x7 you'd access it with (y - 1) * 7 + x ( e.g. [x3, y6] would equal x(39)

I'm not sure if this helps you or makes enough sense.
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,289

### » Thu Jul 01, 2010 4:31 am

Wouldn't the array object solve this by using a z?
For example you could set your 5x5 array with 4 different numbers by setting the array to 5x, 5y, 4z.
You would then have 4 slots to store info at all 25 locations.
It's pretty much like the Perlin plug actually, cept the plug generates a random number for you.

[code:3w0x4jck]+ System: 2=2
-> Array: Set index (1, 1, 1) to 2[/code:3w0x4jck]
B
178
S
50
G
205
Posts: 8,684
Reputation: 127,211

### » Thu Jul 01, 2010 8:18 am

Thanks for the input guys .

Again my lack of any real maths skills may hold me back.

The array I'm currently using is multi dimensional so I'll try to add a few more 'Z' slots/cells/whatever they are called. Currently though it just stores whether the cell is land or sea and the number of land neighbours it has so I can run a few passes of "Cellular Automata" on them.

I've also got it to make a basic sea depth and land height over the map.

This is really my first play with arrays so I'm expecting this to be a long bumpy ride.
B
46
S
23
G
7
Posts: 459
Reputation: 6,763

### » Thu Jul 01, 2010 10:09 am

For a map like that the simplest way would be to have the z set to 5.
The first slot for land or water. That could be set as either a negative or positive number. 1, and greater equals land, less than 1 equals water.
The other 4 slots would be for if it has a tile next to it. Basically the cell at x1,y1, z2 would be the x,y coord subtracting 1 from the current x. Then x1,y1,z3 would be the current y minus 1. Z4 would be current x + 1... etc. And you would just set the value to a 1 or 0 for if something is there or not.
You could even simplify that to have just two z slots by using a counting system.
Example:
(x1,y1,z2)'s value might be 1 meaning that there is only one tile next to it, and its position is current x minus 1, or to the left.
(x1,y1,z2)'s value might be 2 meaning that there is only one tile next to it, but its on top.
Basically you just add 1 going around the tile... ehh its simplified, and yet more complicated. Especially when you start having to take into account the fact that the array object is not zero based.
B
178
S
50
G
205
Posts: 8,684
Reputation: 127,211

### » Thu Jul 01, 2010 10:43 am

Thanks newt.

Your explaination is similar to my neighbours thing. I check in 8 directions from the current cell, if that cell is land or 1, I add 1 to a global variable then store the global variable in the z2 cell of the current cell, clear the global variable and move onto the next cell.

Currently in the map each cell in the array represents a 4x4pix tile on screen. Now I'm going to have another play and see if I can break down the map to 2x2pix tiles using your explaination.

I've learned more about Arrays in a day than I have in my whole life thanks to you guys and Construct.

B
46
S
23
G
7
Posts: 459
Reputation: 6,763

### » Thu Jul 01, 2010 7:02 pm

Ah, now I see! I got you wrong. I thought you wanted to dynamically resize an array according to some kind of higher and lower resolution (like a fake zoom in/out, or similar to the mipmapping). Sorry, and good luck with your project
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,289

### » Thu Jul 01, 2010 9:39 pm

I love that you're generating maps via cellular automata. If you want another challenge, try doing it with Perlin noise (it makes for some excellent landmasses!)
B
2
S
1
G
2
Posts: 48
Reputation: 896

### » Thu Jul 01, 2010 10:05 pm

[quote="Tube":33aflx63]I love that you're generating maps via cellular automata. If you want another challenge, try doing it with Perlin noise (it makes for some excellent landmasses!)[/quote:33aflx63]

Thanks .

I know we've got a perlin noise plugin but I've never used it.

This is a learning excerise for me, I'm a really terrible programmer and a math dunce, so I set myself a challenge to learn a bit about arrays & procedural generation algorithmns.
B
46
S
23
G
7
Posts: 459
Reputation: 6,763

### » Fri Jul 02, 2010 6:32 pm

Hello again.

Can someone tell me why in this .cap it makes too many objects from my Array?

http://dl.dropbox.com/u/1646976/arrayproblem.cap

It creates the right number of black sprites(5) = Array Value 1

But creates twice the amount of red sprites that there should be. I have tried using the "Z" index in the compare condition too but still get the same outcome.

I have tried a loop to but it goes on forever no matter what I try.

Any help would be great.

B
46
S
23
G
7
Posts: 459
Reputation: 6,763

Next