A bug with "While"?

For questions about using Classic.

Post » Fri May 15, 2009 1:15 pm

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 :wink:

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 :

[code:2nxww7id]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 : [url:2nxww7id]http://www.zoglu.net/trucs/bugwhile.rar[/url:2nxww7id]

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?
B
8
S
4
G
5
Posts: 32
Reputation: 2,816

Post » Fri May 15, 2009 1:42 pm

Looks like a bug, best submit it to the tracker.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Fri May 15, 2009 2:01 pm

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 :)
B
8
S
4
G
5
Posts: 32
Reputation: 2,816

Post » Fri May 15, 2009 2:04 pm

Until it's fixed, you can use the 'Repeat X times' condition to work around it.
B
3
S
2
G
5
Posts: 1,777
Reputation: 5,529

Post » Fri May 15, 2009 3:32 pm

Thanks for the advice, and keep up the good work :)
B
8
S
4
G
5
Posts: 32
Reputation: 2,816

Post » Fri May 15, 2009 4:47 pm

yea don't bother ever using while, it's fudged :mrgreen:
B
25
S
3
G
6
Posts: 1,197
Reputation: 5,620

Post » Fri May 15, 2009 5:21 pm

Yet this option exists, and is very useful as long as it works, IMO :wink:
B
8
S
4
G
5
Posts: 32
Reputation: 2,816

Post » Mon May 18, 2009 10:28 pm

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?
B
2
S
2
G
4
Posts: 171
Reputation: 1,792


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests