User Tag List

Results 1 to 4 of 4

Thread: ForEach Problem

  1. #1
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleiOS Export ModuleSWF Export Module
    Eliyahu's Avatar
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    1,523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ForEach Problem

    Yet again, ForEach is failing me
    I have enemies, and they die via bombs, so what I'm trying to do is count how many enemies each bomb kills so I can correctly give bonuses for Double Kills and Triple Kills.
    I do a ForEach loop through the enemies, they get the proper health subtractions, then I've tried SEVERAL ways to get the count, none of them working.

    1
    First I tried putting in the ForEach loop, after health subtraction, If On ForEach Loop and Health of Enemy <= 0, Add 1 to kills (Global Value). I've also tried setting kills to kills+1 to no avail. I have determined that fastloops creating particles wasn't interfering. Oh and to give more info, kills was Always set to 0 in the first event, then I read the value of kills after the ForEach loop to determine what to do.
    To see what was going on, if kills > 0 I would add the value of kills to a visible List. What I observed was SOMETIMES it would work, but a lot of times instead of saying 2, it would do 1 then 1. But the health subtraction occured in 1 frame. There's no possibility it could occur in multiple frames because I remove the bomb object that the condition is dependent on to subtract health. Also, the foreach loop was properly destroying the enemies in 1 frame as I observed via pausing.

    2
    A second idea I had was to count the enemies. Let's use the global value kills again. In my first event I set kills to the number of enemies. Right before I need kills, after all health determination and destruction, I would set kills to kills minus the number of enemies. This SHOULD have yielded the number killed, but it was always giving 0.

    I have no idea what to do, if anyone can help me, thank you very much. I've spent too much time on such a silly problem :'(

    Thank you
    -Eliyahu

  2. #2
    Clicker iOS Export Module

    Join Date
    Feb 2010
    Location
    Behind the tree!
    Posts
    200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: ForEach Problem

    You can have a foreach loop call another foreach loop (nested foreach loop). So you can loop through the bombs then loop through the enemies.

    Also make sure you are using the loop with object selection, so mmf know which to pick, rather than the foreach loop without.

  3. #3
    Clicker Multimedia Fusion 2 Developer

    Join Date
    Jun 2006
    Location
    Darlington, UK
    Posts
    3,298
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: ForEach Problem

    Perhaps use the Select Object?

    It can count the number of objects of a type that match the conditions.

  4. #4
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleiOS Export ModuleSWF Export Module
    Eliyahu's Avatar
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    1,523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: ForEach Problem

    A nested ForEach loop wouldn't solve any problems, and I am using the object selection loop.
    I cannot use Select Object, Dynasoft, this needs to be able to run in flash.

    RickyRombo helped me and we discovered that NObjects("enemy") was only being updated every frame, not when Destroy was called, so that's why my second idea didn't work.
    So I fixed it to keep track of the last frame's count, then compare it to the new frame's count, and determine how many kills occured.

    The problem is still that I get 1 then 1 instead of 2. This must be a ForEach problem that its effects are not taking place within the single frame they should. Is there any solution to this bug?


    EDIT: I just fixed it, it was really weird and I have no idea why it works now. I moved the action that was destroying the bomb. It looks like it was staying alive for 2 frames, but I considered the order of events and that should not have happened. This was a really weird problem.... But at least it works now!
    Thanks all

Similar Threads

  1. ForEach loop for Object problem
    By King_Cool in forum Multimedia Fusion 2 - Technical Support
    Replies: 4
    Last Post: 10th April 2013, 11:00 PM
  2. Foreach
    By AndyH in forum iOS Export Module Version 2.0
    Replies: 10
    Last Post: 31st January 2012, 06:47 AM
  3. ForEach problem
    By mobichan in forum File Archive
    Replies: 0
    Last Post: 21st October 2010, 12:58 AM
  4. How do i do a ForEach
    By Spryz in forum Multimedia Fusion 2 - Technical Support
    Replies: 2
    Last Post: 12th May 2008, 12:45 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
  •