This forum is currently in read-only mode.
0 favourites
  • 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.






    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.





    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 .


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

  • 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.

  • 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.

    + System: 2=2
    -> Array: Set index (1, 1, 1) to 2[/code:3w0x4jck]
  • 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.

  • 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.


    (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.

  • 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.

    <img src="">

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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

  • 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!)

  • 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!)

    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.

  • Hello again.

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

    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.

  • It's the "For each element". For each cycles each z each pass, so basically its running z2 twice.

    Better to do a regular loop here.

  • Thanks newt I had a feeling it was doing something like that.

    Can you or anyone help with creating the checking loop? I have tried but however I structure it, it seems to be infinite and just keeps spawning objects. I also downloading an example but that seemed to loop infinitely too.

    But I would expect that as I've never used loops before. Construct is great for learning new stuff.


  • Ok one thing is you were checking x,and y coords, but you need to check the value at x,y,and z.

    As well as set the value at x,y,and z.

    Also your using an older version this cap wont work for you.

    Sorry Im using the latest unstable, but here's the code if you don't want to download.

    btw the value's in the array are set to zero by default(if you didn't already know that).

    + System: Start of layout
    -> Array: Clear array with 0
    -+ System: Repeat 5 times
    + System: Repeat 5 times
    --> Array: Set index (random(5)+1, random(5)+1, 1) to 1
    --+ System: For "x" from 1 to 10
    ---+ System: For "y" from 1 to 10
    ----+ Array: Value at (LoopIndex("x"), LoopIndex("y"), 1) Equal to 1
    ------> System: Create object Sprite on layer 1 at (LoopIndex("x")*10-5, LoopIndex("y")*10-5)
    ----+ Array: Value at (LoopIndex("x"), LoopIndex("y"), 2) Equal to 0
    ------> System: Create object Sprite3 on layer 1 at (LoopIndex("x")*10-5, LoopIndex("y")*10-5)[/code:y28wftyl]
  • Thanks again newt.

    I've updated to the newest unstable build because when I remade your example it didn't work, I'm guessing the Array Object was bugged in 0.99.82 or whatever version I was using.

    I can't see this being the last time I'm going to need help with loops though .

    Thanks again

  • Python lists work very well, if you aren't afraid of using Python. You could set a few methods to easily modify the array and retrieve information and then leave the rest in backend.

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