The Daily Click ::. Forums ::. Klik Coding Help ::. Destroy objects and their 'children'
 

Post Reply  Post Oekaki 
 

Posted By Message

SolarB



Registered
  26/12/2011
Points
  564
11th January, 2012 at 16:29:56 -

Scenario: Multiple objects (soldier units) of the same type have loop linked detectors and health bars. IDs for each are updated on creation of a new unit. So far so good, units have separate collision detectors and health bars.

Problem: When a unit is killed (and hence destroyed) all ids get totally muddled and generally weird stuff happens.

On Loop ("Dead Soldier")
ID (Soldier) = Loopindex ("Dead Soldier")
+ Health of (Soldier) = 0
+ ID of (Detector) = Loopindex ("Soldier Health") //or// ID of (Soldier)
+ ID of (Health Bar) = Loopindex ("Soldier Health") //or// ID of (Soldier)
--> Destroy Soldier, Detector and Health Bar


What is the problem?

I am really getting sick of MMF2 and object instance handling. Much need of a parent/child system!! Construct - here we come

Thanks for any help! It should be obvious that there is more to the code than just the above, standard stuff really and no issues there, ie. on creation of new unit, spread values in all objects etc.

 
My Open Source Examples: http://bit.ly/YyUFUh

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1971

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
11th January, 2012 at 18:23:29 -

There's nothing wrong with that event. You've gone wrong somewhere else - most likely, you haven't spread the values properly (eg. you tried to spread a value in the same line as creating a new object, which obviously won't work). It's easy enough to check using the debugger.

However, you should NOT be using fastloops or spread values for this at all (or separate detector objects either, for that matter) - you're just trying to make life difficult for yourself. Use MMF2's automatic object matching - it's so much simpler and more efficient.

 
n/a

SolarB



Registered
  26/12/2011
Points
  564
12th January, 2012 at 06:35:16 -

Hey Sketchy,

Values are only spread when Soldier ID = 0 (ie a new soldier is created). But when one is destroyed, all hell breaks loose. Detectors are necessary for good collision detection - i want my units evenly spaced when they get to the target point.

Auto object matching? You mean just let mmf do it's thing? Dunno if that will work, units also have bounding boxes when selected as per nivram's RTS Movement tute.

Thanks for the input!

 
My Open Source Examples: http://bit.ly/YyUFUh

SolarB



Registered
  26/12/2011
Points
  564
12th January, 2012 at 08:37:52 -

EDIT:

Solved by ALWAYS spreading values in all related objects. Seems pretty inefficient though...

 
My Open Source Examples: http://bit.ly/YyUFUh

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1971

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
12th January, 2012 at 12:00:19 -

Yes, letting MMF2 "just do its thing" will work, if you do it right.

If you're determined not to do that, then you'd still be better off using the ForEach extension (much more efficient when you have a lot of objects), and instead of spreading values you could just set the value to the value of a counter/global/etc, and add 1 to that each time you create a new object.

I'm guessing the previous problem might have been that you ran a fastloop according to the number of objects, but didn't re-spread values when an object was destroyed. So if you had three objects, with values 0, 1 and 2 - and then deleted the first one, the next time you would only run the loop twice (two objects) so the loopindex would stop at 1 and the object with a value of 2 would be ignored.





 
n/a

Jenswa

Possibly Insane

Registered
  26/08/2002
Points
  2723
20th January, 2012 at 17:51:28 -

MMF's automatch system actually works quite good. It just finds the right object without searching IDs. Not sure how your system works, but something with a value for HP in an object and when HP reaches 0 that object will be destroyed.

And now I see your problem, you're arranging HUD elements relative to the position of the object and you want to have the HUD elements to display the information of that object. And the IDs will do this job for the HUD and the object. So when the object is destroyed, the HUD should be destroyed too.

By using MMF's automatch system you could destroy healthbars when they reach zero or less health, no need for IDs in this case. And object the detector, if that detector is just overlapping a little part of the object you could use this condition to test for. So when the object is destroyed, the detector isn't overlapping it anymore and the detector can be destroyed too.

Will this help?

 
Image jenswa.neocities.org

SolarB



Registered
  26/12/2011
Points
  564
21st January, 2012 at 22:53:23 -

Thanks Jenswa, this is probably useful but I think I'm going to stick with constant value spreading and loop matching for now, seems safer.

Cheers!

 
My Open Source Examples: http://bit.ly/YyUFUh
   

Post Reply



 



Advertisement

Worth A Click