-
ForEach issue
I seem to be having a problem with the ForEach object. I have a ForEach loop that compares fixed values of a qualifier and also compares an alt var for health and an alt var for enemy type. It is something like this:
+EnemyHealth = 0
--Start ForEach loop "DestroyEnemy"
+On ForEach loop "DestroyEnemy"
+Fixed(qualifier) = Fixed ForEach "DestroyEnemy"
+Health(qualifier) = 0
+EnemyType(qualifier) = 1
--Add 1 to counter
--Destroy(qualifier)
+On ForEach loop "DestroyEnemy"
+Fixed(qualifier) = Fixed ForEach "DestroyEnemy"
+Health(qualifier) = 0
--Start loop "DeathFx"
--Destroy(qualifier)
In this scenario, I expect that when I kill an enemy of type 1, they will be destroyed and no death fx loop will be run. But I find that the fx are being created anyway.
Is this a bug? If it isn't is there a workaround?
Mobichan
-
Re: ForEach issue
You shouldn't need to test fixed values, you should just be able to ForEach on the qualifier and it should work.
-
Re: ForEach issue
I am using the fixed value comparison, since I sometimes need to run a sub fastloop and return to the ForEach loop. I've never actually been able to make ForEach loops work without the fixed value comparison.
-
Re: ForEach issue
I have uploaded a simple example of what I am having trouble with. I used to use nested fastloops, but converted my code to use ForEach loops. Now I am having this issue.
File is here:
http://www.clickteam.com/epicenter/ubbthreads.php?ubb=showflat&Number=209756&#Post209 756
-
Re: ForEach issue
Sorry to bump this, but can anyone at least explain what is happening here? I can't figure out why an object that is destroyed in one event line is still able to be recognized by a subsequent event.
-
Re: ForEach issue
I wonder if objects are only actually destroyed at the end of a fastloop - try setting a value on the objects along with destroying them, and test for that within the loop (that is, + HasBeenDestroyed("Enemy") == 0)
-
Re: ForEach issue
I didn't have any issues using a normal, nested fastloop setup. I only noticed this with the ForEach loop.
DavidN: I tried your suggestion and it would seem that having another var to check against stops the problem (confirming your suspicion). But if you need to waste a variable to make this work, that seems to be a big negative to using ForEach over nested fastloops.
Can Ross confirm any of this?
-
Re: ForEach issue
don't objects continue to exist for the entire frame after they are 'destroyed', not just a fast loop? IE, calling "destroy" on an object doesn't actually do a thing to the object until the end of the code. Any code further down the line will continue to reference them, won't it? Thats not unique to fast loops or foreach
-
Re: ForEach issue
Pixelthief, that's correct.
From what I remember, when you destroy an object, an internal flag is set to true, and at the end of a game frame, all objects with that flag will be removed.
-
Re: ForEach issue
yeah those are two things MMF3 better be able to do- instantly remove objects, and create objects dynamically runtime according to parameters. From what i understand theres no way extensions could do either of those