How do I remove an array with specific value?

0 favourites
  • 3 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • Hi, I'm creating a "blocks" game (Tetris style) blocks are created randomly on five columns. I'm trying "remove/stop" an X position when a column is filled with blocks.

    I have an Array (1d) with a 5 width and 1 height with X positions where the blocks will be created. The Array it looks like this:

    X0 X1 X2 X3 X4
    0 96 192 288 384

    I have a condition to create the blocks: Every X seconds

    Create object: Block

    Layer: 0

    X: MyArray.At(int(random(MyArray.Width)))

    Y: 200

    OK, this works as expected to create blocks on a random column. My problem comes now:

    Imagine I want to stop creating blocks from column 3 (192 X position) and later column 4 (288 X position):

    I can create something like Delete index 2 from X axis but then the rest of the Array it's sorted like:

    X0 X1 X2 X3
    0 96 288 384

    So now for delete "288", it's index "2" again... I don't know if it's easy to understand... My problem it's I don't know how to remove any index with value 288 in the array.

    If you know another way to create objects from "a list" of positions and how to modify the list I appreciated your help. πŸ™πŸ»

    Before, I tried to create the blocks with something like choose(0,96,192,288,384). But I don't know either like remove some values of these options.

    Many thanks in advance! ;)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Why use the array? You can put five instances of an invisible "Spawner" sprite at these coordinates. Pick a random Spawner instance and use it to spawn a block. When you need to disable one Spawner, either destroy it or set an instance variable on it marking it inactive.

  • Hi dop2000, you are right!

    I don't know why I focused to use an array... if there is a more simple way. πŸ˜…

    I created a little working example in case it's useful for other people.

    Thanks for the help! πŸ™πŸ»

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