0 Favourites

How do I count number of objects around each instance?

  • This has been troubling me for a while...

    I have a bunch of sprites (A) in a tile formation (20*20 sprites for a total of 400) and I want each instance of this object to count how many sprites (A) are around it, then set an instance variable (A) as that number.

  • See my example in minesweeper game:

    The sample show how many bombs around certain tile.

  • alextro

    Thank you very much! You will be put under the "special thanks" part of my credits (currently only 4 in the entire credits!)

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Sweet! Notice me when your game is available.

  • alextro

    I am having trouble discerning what the put_bomb sprite does, and how it is found. I have made my own test to try to replicate the action, but it is not working.

    Can you tell what is going wrong?

  • You should check sprites object in projects tree, put_bomb just a small sprite to set where the mines will be placed. There are some miss calculation in your capx.

    First based on your sprite size, offset value should be set as 50 not 25. Then evaluating distance retrieved from pythagoras equation: ceil(sqrt(50^2+50^2)) will result 71.

    here I edited yours:

  • The program works great, but there are a few kinks.

    There is an action that changes the sprite's frame to the instance variable, and when it is run I get this.

    The problems are circled here:

    The problem seems very random... Maybe construct 2 is conscious.

    (You may need to zoom to 50%-33% to view the whole image. Also, the program runs very slowly. Is it the amount of objects on screen? No, I attempted to make the grid smaller (3 by 3) and it still has lag.)

  • Please check the edited capx I put here:

    You should check sprites object in projects tree, put_bomb just a small sprite to set where the mines will be placed. There are some miss calculation in your capx.

    First based on your sprite size, offset value should be set as 50 not 25. Then evaluating distance retrieved from pythagoras equation: ceil(sqrt(50^2+50^2)) will result 71.

    here I edited yours:

    It all went okay and fast.

  • alextro

    Please check the edited capx I put here:

    > You should check sprites object in projects tree, put_bomb just a small sprite to set where the mines will be placed. There are some miss calculation in your capx.

    > First based on your sprite size, offset value should be set as 50 not 25. Then evaluating distance retrieved from pythagoras equation: ceil(sqrt(50^2+50^2)) will result 71.

    >

    > here I edited yours:

    >

    It all went okay and fast.

    I just redownloaded it and played it in debug, and it runs quickly, but still has errors:

    This image has only been cropped, and the code was not altered in any way. I ran the program again, with some random instances having an incorrect inst. var.

  • Removed unnecessary condition. Should working correctly now >>

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