Detecting multiple destroyed duplicated objects?
I'm trying to add to a value when an object gets destroyed... The problem is that if two of the same object gets destroyed in one game loop, it's only adding 1 to the value.
What sort of event condition or actions should I use to make sure it's adding 1 to the value for every object that is destroyed?
Right now I just have a condition being checked for whether the object should get destroyed, then it's adding 1 to the value and destroying the object.
Re: Detecting multiple destroyed duplicated objects?
Weird. I that out myself now and it went fine. Would you mind if I checked your mfa real quick?
Re: Detecting multiple destroyed duplicated objects?
Weird... Well the mfa is huge... Do you think you could just post your test mfa and that way I can see what I'm doing wrong? (or what you did right)
Re: Detecting multiple destroyed duplicated objects?
You can use a fastloop to check all your enemies whenever they need to be destroyed.
Re: Detecting multiple destroyed duplicated objects?
Re: Detecting multiple destroyed duplicated objects?
That example MFA is helpless because it uses an event that is already triggered for each object the user clicked on in one loop.
Depending on what conditions you use to destroy and object and add to a counter, it may or may not count multiple objects. Note that multiple objects may be selected by one condition, and any actions on that type of object affect all selected objects. This means one event vs several objects.
Gerald999 made a related example recently...
http://www.clickteam.com/epicenter/ubbthreads.php?ubb=showflat&Number=217068#Post2170 68
Re: Detecting multiple destroyed duplicated objects?
Sorry bout that, hm.
Still making my way around this program.
Re: Detecting multiple destroyed duplicated objects?
You could use the Select Object to count all the objects that matched the conditions.
(doesn't work with any of the exporters, i.e. Flash/Java/mobile/etc)
Re: Detecting multiple destroyed duplicated objects?
Yeah, sorry, I was under the impression that this was for one of those exporters. Go with Dynasoft's Select Object Extension ;)
Re: Detecting multiple destroyed duplicated objects?
fastloop is the real soultion, and would work with any future export type.
Re: Detecting multiple destroyed duplicated objects?
Thanks for all the responses guys.
I've been doing good keeping my game export friendly and I'm really trying to avoid using extensions that won't work in Flash/Java/etc. The type of condition event I'm using to destroy the objects isn't very friendly with keeping track of how many objects are destroyed during a loop, so it looks like I'll go with the fastloop suggestion.
I just kind of wanted to avoid using more fastloops because there's a lot of these same objects on the screen and that means every time one gets destroyed I have to loop through all of them to see if any others got destroyed during that loop also. Which just means it's going to be rather slow... But I guess I don't really have much choice otherwise.
I'll try to play around with some of the collision event options and see if that might work out.
Re: Detecting multiple destroyed duplicated objects?
Unless you have 50+ enemies, I don't think you will need to worry about slowdown. Besides, the fastloop for this should only run when an enemy dies. So the only time you "might" see slowdown is on the frame of the enemy's death.
Re: Detecting multiple destroyed duplicated objects?
There can be over 300+ of these objects at once... So yeah, that's why it's a pain to do a fastloop through them. (not to mention, I'm already running a fastloop through them to check for movement, so it's basically having to look through 600+ objects per loop. Not the most speed efficient situation)
I've implemented the fastloop method and I'm not noticing any real slowdown for now. I think the only good thing about this situation is that this event only happens every so often when the player destroys the object. For the most part, the objects just stay on screen. Not to mention they get destroyed during the loop, so it helps to take a bit of pressure off the process.
But I still wish there was a less loop intense way of doing this without using unfriendly extensions.
Re: Detecting multiple destroyed duplicated objects?
What is the exact condition you are using to check if objects should be destroyed? Can you post a simplified example?
I know of a lot of work arounds and I'm pretty sure I could come up with something that doesn't need fastloops if I had an example.
Re: Detecting multiple destroyed duplicated objects?
The condition is basically just checking to see if the object's "damage" alterable value is at a certain number and then destroying the object.
Re: Detecting multiple destroyed duplicated objects?
I would say that if you aren't seeing slowddown, then don't worry too much about it until you do.
Re: Detecting multiple destroyed duplicated objects?
Does String Parser 2 object reliably work with Flash and Java runtimes? If so, you can avoid fastloops using a rather hacky workaround. It works because expressions (such as 'set alterable value to...') loop for each copy of the object selected, and SP2 has the ability to set a new value for the string parser from within an expression.
Does that make sense?
Code:
// Counting bad guys
Bullet overlaps bad guy
--- String Parser: Set string to "0"
--- bad guy: Set alterable string A to:
set string of string parser to itself as a number + 1 (see explanation below)
--- bad guy: Destroy
--- Counter: Add value of String Parser's string to counter.
The funny formula (put this way because I don't have access to MMF right now) retrieves the string from string parser ("0") turns it into a number (0) and adds 1 to it (1). It then turns it back into a string ("1") and sets the string to that value, so string now == "1".
Object Expressions repeat for each object being processed, so this process will add '1' for each bad guy you're destroying.
You then simply add the numeric value of the string in String Parser into the counter.
I know you don't want to use extensions if possible, but there's a chance this one will be okay, because I believe it's become an old staple of MMF's and will likely continue to be updated (I think) for future versions and exporters.