Arrays

This forum is currently in read-only mode.
  • Speaking of Python, it also has array objects that can be imported via the internal array module or the external NumPy module. It may be a bit more than you'd want to bite off right now, though. The 3-D array that you're using should work fine, too.

    Don't short-sell your abilities, Minor. I've considered doing this sort of procedural generation in the past, but the idea scared me away before I even got started.

    Anyway, just because I feel compelled to point it out, this application practically begs for bitwise operations. Unfortunately, I don't see any support for them in Construct, other than through Python.

    Basically, you can just use a 2-D list or array which contains integer values. Each integer value can have different bits set for any given on/off or true/false state that you need to track. For instance, you can keep the status of bordering land in the four cardinal directions in four bits. Expressing the values in binary notation (with 0b prefix) makes it more obvious what bits are set.

    0b0001 (if land to north)

    0b0010 (if land to south)

    0b0100 (if land to west)

    0b1000 (if land to east)

    You can set the bits with the OR operator (|):

    0b0001 | 0b0100 ( = 0b0101)

    and test them with the AND operator (&):

    0b0111 & 0b0100 ( = 0b0100, testing for bit 3 set)

    Bah, too much to go into here, really. Feel free to ignore the whole bitwise thing... Mostly just me reminiscing about 8-bit computer programming practices that aren't widely used anymore.

    Keep up the good work. I like your creations so far.

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

    Yep I'm very afraid of python Mipey, too many brackets & stuff. Proper written programming languages and me don't mix, I have tried since the late 80's but nothing ever sticks. The only written language I ever got a decent grasp of was AMOS on the Amiga, and when I say decent I mean it went further than

    10 print "Hello"

    20 goto 10

    Speaking of Python, it also has array objects that can be imported via the internal array module or the external NumPy module. It may be a bit more than you'd want to bite off right now, though. The 3-D array that you're using should work fine, too.

    Don't short-sell your abilities, Minor. I've considered doing this sort of procedural generation in the past, but the idea scared me away before I even got started.

    Anyway, just because I feel compelled to point it out, this application practically begs for http://en.wikipedia.org/wiki/Bitwise_operation">http://en.wikipedia.org/wiki/Bitwise_operation</a>]bitwise operations. Unfortunately, I don't see any support for them in Construct, other than through Python.

    Basically, you can just use a 2-D list or array which contains integer values. Each integer value can have different bits set for any given on/off or true/false state that you need to track. For instance, you can keep the status of bordering land in the four cardinal directions in four bits. Expressing the values in binary notation (with 0b prefix) makes it more obvious what bits are set.

    0b0001 (if land to north)

    0b0010 (if land to south)

    0b0100 (if land to west)

    0b1000 (if land to east)

    You can set the bits with the OR operator (|):

    0b0001 | 0b0100 ( = 0b0101)

    and test them with the AND operator (&):

    0b0111 & 0b0100 ( = 0b0100, testing for bit 3 set)

    Bah, too much to go into here, really. Feel free to ignore the whole bitwise thing... Mostly just me reminiscing about 8-bit computer programming practices that aren't widely used anymore.

    Keep up the good work. I like your creations so far.

    Thanks encouragement and for the info . Bitwise does seem like something that would make what I'm trying to do a bit easier.

    Right now on with an Array-Loopy question.

    How would you go about extending a loop? for example: Below is my Array #=sea 1=land

    #####

    ##11#

    ##1##

    #####

    #11##

    #1###

    #####

    I want to scan the array to find land that is connected to another piece of land and give each the same number in a "z" index/cell/slot/thingy. Then find the next land unconnected to the first and find the land connected to that land etc. So my array above would look like this:

    #####

    ##11#

    ##1##

    #####

    #22##

    #2###

    #####

    I know how to use the array to check neighbours as I use that for the Cellular automata part of the project. It's just looping through grouping them via a number per land mass and finishing the loop without it going on for ever.

    Does that make any sense?

    Thanks again for all the help. I really am learning stuff here that I never thought I'd learn .

  • That's getting into more difficult territory. If Construct's image manipulator or canvas had a flood fill, it would be fortunate, because they could be used as helpers for this. Alas... it is not so.

    The simplest way that i can think of to do that would be like so, in my own weird pseudocode:

    untouched = -1 # needs to b a value different than the number 1 and above
    water = 0
    z = 1 # setting this as static outside the loop makes the routine operate on the array as if it were a 2-d array, only at the z depth set.
    
    func flood_fill(array, x, y, z, fill, border):
       # Fills all connected cells surrounded by border, starting at array(x, y, z), with the value in fill.
       # Some flood fills use connected cells of same value instead of using a border.
       # flood fill algorithms can be 4-directional or 8-directional (allows diagonals to be considered connected)
       ... a bunch of code here ...
    
    count = 0
    for y = 1 to array.y_size:
       for x = 1 to array.x_size:
          if array(x,y,z) = untouched:
             count = count + 1
             flood_fill(array, x, y, z, fill=count, border=water)[/code:2bx2ys0n]
    
    I've not programmed a flood fill routine before. It should certainly be possible to implement as a function in Construct, but would certainly be easier in Python. Python doesn't work well with Construct's Array object, but that's possible, too.
    
    I'd probably look for a non-recursive algorithm using a stack to work from, since it looks as if another Construct array could be suitable for use as a stack.
    
    Maybe someone else will have an easier idea.
  • Thanks for the info Silent Cacophony.

    I'm starting to think this is way too complicated for me at the minute. Best go back with something a little more simple regarding Arrays & Loops, I was on a bit of a roll and started to get ahead of myself.

    Still I have learned a lot so far. I got a nice little map generator going, not bad for a programming thicko .

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • That looks pretty cool, Minor

    Anyway, if you determine that you need to implement such an idea, it wouldn't be too bad to implement in Python for one of us who program with it. I know of a nice flood fill algorithm in python that could be trivially adapted to this, but a few very specific details would be needed in order to make it correctly. A lot easier to insert python code than Construct events, too.

    However, some extra overhead would be introduced, since Python cannot read Construct arrays, currently. You'd have to construct a Python list copy of the Construct array from Construct events, and call the python code, which will operate on the list, then copy the result back to the Construct array. This would likely be done in a Construct function, each time a flood fill was needed.

    Just something to think about. As I mentioned, I think it's quite possible with only construct events, too, but it would be more difficult to copy between projects.

  • You reeealy should check out the Perlin plug. With it you wouldn't have to check nearest neighbor, since the random data generated ensures that cells at a certain height will be surrounded.

    All you would need to check is if it is at sea level or not.

  • You reeealy should check out the Perlin plug. With it you wouldn't have to check nearest neighbor, since the random data generated ensures that cells at a certain height will be surrounded.

    All you would need to check is if it is at sea level or not.

    Will do newt.

    I think I've come to the end of my capabilites with this little excerise anyway, the things I would like too add seem way out of my capabilities at the moment.

    Still I've learned some programmy stuff - loops and arrays.

    Thanks guys.

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