A bug with "While"?

This forum is currently in read-only mode.
From the Asset Store
Match same tiles with each other as fast as you can and earn more score during a limited time!
  • Hi,

    I've found what could be a little bug, or maybe it's just me who doesn't do it right (I'm new to Construct), so I preferred asking for help before

    At first there are 1250 "Sprite" objects on my layout. I want to remove them so there are only 800 "Sprite". I know there are hundreds of methods to do so, but I tried using this code :

    System: Start of layout
    

    Sprite2 : Set 'OBJ' to Sprite 0 .Count

    Sprite2 : Value 'OBJ' Greater or equal 800

    Sprite: Pick one at random

    Sprite2 : Subtract 1 from 'OBJ'

    Sprite : Destroy[/code:2nxww7id]

    So it removes one "Sprite" at each tick until the number reached 800. But in order to remove all of them at once, I've added a "While" condition so they could be destroyed more quickly. This is what this cap does : http://www.zoglu.net/trucs/bugwhile.rar

    However, when I run it in the end there are about 860 sprites, while the "Sprite2"'s variable 'OBJ' has reached 800. Like if sometimes the variable was decremented but no "Sprite" was destroyed.

    Also, if I try to replace the "Sprite2 : Subtract 1 from 'OBJ'" by a "Sprite2 : Set 'OBJ' to Sprite.Count", it goes into an infinite loop. That's weird, because one "Sprite" is supposed to be destroyed at each loop, so the object count should decrease.

    So... I know I'm not following the best way to do it, but it definitely looks like a bug. Or maybe I'm just doing it wrong from the beginning. What do you think about this?

  • Looks like a bug, best submit it to the tracker.

  • I did it.

    Maybe the final object count when I add the While depends on the PC's speed. My PC is quite slow (1.6 Ghz processor, and a very, very old graphics card).

    Anyway I hope you'll find why it doesn't work

  • Until it's fixed, you can use the 'Repeat X times' condition to work around it.

  • Thanks for the advice, and keep up the good work

  • yea don't bother ever using while, it's fudged

  • Yet this option exists, and is very useful as long as it works, IMO

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • i guess this is not a bug with while, but a bug in how objects persist in the timeframe of a single tick. i think that the 'pick random' condition picks a random object from the set of objects present at the start of the current tick, and ignores any changes (objects being destroyed) made to this set during the current tick.

    i've had similar problem with objects that are not present in the first tick ('destroyed on startup') and created en masse in a loop during the 'on startup' event. because construct couldn't operate on these objects in the same tick, i worked around that by 'call function after delay'. i though it was a startup thing, but your 'while'-problem is oddly similar.

    does this ring any bell with the devs regarding object handling?

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