User Tag List

Results 1 to 5 of 5

Thread: Handling the Hp of multiple opponents

  1. #1
    Clicker Fusion 2.5 DeveloperiOS Export ModuleSWF Export Module
    Yima's Avatar
    Join Date
    Feb 2008
    Location
    Sweden
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Handling the Hp of multiple opponents

    I am making a platform game where at certain times the player will be faced with multiple opponents (mushrooms in the case) of the same kind. Each opponent has a hp value, and the idea is of course that the opponent should die when it's hp reaches 0. Here's some code:

    Always
    - Mushroom: Spread value 0 in ID

    Always
    - Start loop checkshroom NObjects(Mushroom) times

    On loop checkshroom
    + ID of Mushroom = Loopindex("checkshroom")
    + Shuriken collides with Mushroom
    - Subtract 1 from Hp(Mushroom)

    On loop checkshroom
    + ID of Mushroom = Loopindex("checkshroom")
    + Hp of Mushroom = 0
    - Destroy Mushroom

    All this does is destroy every Mushroom on the screen. It seems like it's the second loop that doesn't work, because if I remove it and change the first loop, where the shuriken hits the Mushroom, so that it destroys the Mushroom at once, each Mushroom will die the way they should.

    If someone could please help me out with this I would be very thankful. I've read a dozen threads about this problem now, and in almost every one of them the code above has been the solution. Still it won't work. Argh...

  2. #2
    Forum Moderator Fusion 2.5 DeveloperHTML5 Export ModuleiOS Export ModuleSWF Export Module
    DavidN's Avatar
    Join Date
    Jun 2006
    Location
    Boston, MA, USA
    Posts
    4,044
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Handling the Hp of multiple opponents

    From looking at just that section of code, you shouldn't need to use a fastloop for this - "Shuriken collides with Mushroom -> Subtract from Hp("Mushroom")" should select one object correctly anyway.

    But if there are other reasons that you have to do it in a fastloop - is it possible that you're using the "Compare two general values" condition to test whether ID("Mushroom") is equal to the loop index? This event doesn't select one specific mushroom - use the "Compare alterable value" condition on the Mushroom object instead.

  3. #3
    Clicker Fusion 2.5 DeveloperiOS Export ModuleSWF Export Module
    Yima's Avatar
    Join Date
    Feb 2008
    Location
    Sweden
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Handling the Hp of multiple opponents

    Quote Originally Posted by DavidN
    From looking at just that section of code, you shouldn't need to use a fastloop for this - "Shuriken collides with Mushroom -> Subtract from Hp("Mushroom")" should select one object correctly anyway.

    But if there are other reasons that you have to do it in a fastloop - is it possible that you're using the "Compare two general values" condition to test whether ID("Mushroom") is equal to the loop index? This event doesn't select one specific mushroom - use the "Compare alterable value" condition on the Mushroom object instead.
    I just solved the main problem. In the code I posted I ignored to include the fact that when the shuriken hits the mushroom, and when the mushrooms hp reaches 0, I start new loops that create hundreds of particles that act like a "splat" effect.

    As soon as I removed these loops from the events, things worked like a charm.

    Kinda weird though.

    Shuriken collides with Mushroom
    - destroy mushroom

    destroys the correct mushroom

    while

    Shuriken collides with Mushroom
    - start loop "createsplat" 100 times
    - destroy mushroom

    destroys all mushrooms.

    Is there any logic to this?

    (also, thanks for the advice - when removing the splat-loops there was no need for doing the spread value stuff at all)

  4. #4
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCSWF Export Module
    Alonso's Avatar
    Join Date
    Jul 2006
    Posts
    681
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Handling the Hp of multiple opponents

    I think I once ran into the same problem and it (apparently) turned out to be that when you run a fastloop before the destroy action, the selected object becomes unselected and the action will apply to all objects of the same kind. You can try running the loops after the mushroom is destroyed, or should it fail too, trigger another condition. Feel free to correct me, though.

  5. #5
    Forum Moderator Fusion 2.5 DeveloperHTML5 Export ModuleiOS Export ModuleSWF Export Module
    DavidN's Avatar
    Join Date
    Jun 2006
    Location
    Boston, MA, USA
    Posts
    4,044
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Handling the Hp of multiple opponents

    That sounds absolutely right - MMF2 forgets about the object selection in the current event when you start a loop. That was a vital clue!

    Apparently it isn't a very easy behaviour to correct in the MMF2 code - I think in this case you can avoid it by creating two duplicate events, one for "start loop 'createsplat'" and another for "destroy mushroom".

    I usually create separate "generator" objects to handle particle effects, and using this setup (Create "generator" at "mushroom", destroy mushroom, loop 100 times using "generator" as the origin point for particles) you can consolidate it into one event.

Similar Threads

  1. Handling Multiple Channel Connections
    By netninja in forum Lacewing
    Replies: 3
    Last Post: 2nd November 2018, 06:42 PM
  2. Session Handling using MMF
    By DJFuego in forum HTML5 Export Module 2.5
    Replies: 5
    Last Post: 11th August 2015, 06:12 PM
  3. Destroying opponents by... bouncing on them?
    By clim in forum Multimedia Fusion 2 - Technical Support
    Replies: 12
    Last Post: 2nd January 2011, 07:52 PM
  4. Unicode handling
    By thewreck in forum Multimedia Fusion 2 - Technical Support
    Replies: 0
    Last Post: 22nd May 2007, 08:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •