User Tag List

Results 1 to 8 of 8

Thread: For Each Loop Scoping does NOT work properly when there are many objects

  1. #1
    Clicker

    Fusion 2.5Android Export Module

    Join Date
    Jan 2007
    Posts
    259
    Mentioned
    5 Post(s)
    Tagged
    1 Thread(s)

    For Each Loop Scoping does NOT work properly when there are many objects

    Hello,

    When I design enemies for my games I always include methods to force proper scoping that should not be needed in order to make sure my enemies scale to an infinite amount. Most of the enemies in my games have their own physics and can become fairly complex so being able to have hundreds of thousands of them all working independently of each other is an important part of my troubleshooting process.

    Any time I have posted an example here using my "verification" method people tell me it isn't needed, but upon removal of it in my games my scoping stops working properly when there are a lot of enemies in the same loop. The same applies for OTHER peoples examples as I have not seen anyone else use the same method I have.

    For example, the following pseudo-code should scale to an "infinite number of enemies"

    Number of Enemies > 0
    - Start For Each Loop "Enemy"

    On For Each Loop "Enemy"
    + Distance between Enemy and Character < 50 pixels
    - Set enemy to "Chase" mode

    On For Each Loop Enemy
    + Distance between Enemy and Character >= 50 pixels
    - Set enemy to "Idle" mode

    This seems to work fine until you start adding numbers. Once you have a solid handful of enemies (5-50) the scoping will no longer work and the "Chase" or "Idle" mode will be applied to EVERY instance of said enemy simultaneously.

    If I add the following code the issue goes away and I can add an indefinite amount of enemies and the scoping works PERFECTLY.

    On For Each Loop "Enemy"
    - Set Counter to Fixed ID of "Enemy"

    On For Each Loop "Enemy"
    + Fixed I of "Enemy" = Counter
    + Distance between Enemy and Character < 50 pixels
    - Set enemy to "Chase" mode

    On For Each Loop Enemy
    + Fixed ID of "Enemy" = Counter
    + Distance between Enemy and Character >= 50 pixels
    - Set enemy to "Idle" mode

    This isn't a big deal to me because I can just add one line of code (and one counter per enemy type) to any line that needs to scope a particular enemy, but I find it intriguing and slightly annoying that the For Each Loop feature does not work as intended when lots of complex objects need to be scoped. I've adapted my entire coding style around this issue so I'm used to it, but it would be nice if fusion could handle the scoping, properly, itself.

  2. #2
    Clicker Fusion 2.5 Mac
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Fusion 2.5+ DLC (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)

    Join Date
    Jan 2015
    Location
    Australia
    Posts
    168
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)
    That's unusual, do you have a sample you can upload? I tried fiddling around with it myself and tried a few different ways to see if I could get the same issue.

    Here's the file I tried it in: loopscoping.mfa

    And a few different ways of doing it:
    methods.png

    Method 1 is probably the option I would use for something like this, seems to be the simplest solution which doesn't require a fast loop

  3. #3
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleXNA Export ModuleUnicode Add-on
    mobichan's Avatar
    Join Date
    Oct 2007
    Location
    Buffalo, NY
    Posts
    3,281
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    I am curious if the condition to start the foreach loop is the cause, since that affects scoping. It might be a crazy hunch, but if you change "Number of enemies > 0" to "Always", do you still see the problem?

    Have you also tried making a new file with your pseudo code approach to see if it might be some corruption in your project file or another set of events interfering?

  4. #4
    Clickteam Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleUniversal Windows Platform Export ModuleInstall Creator Pro
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    BartekB's Avatar
    Join Date
    Aug 2013
    Posts
    622
    Mentioned
    12 Post(s)
    Tagged
    0 Thread(s)
    Interesting issue. I also use for each loops extremely frequently (as in, around 95% of lines of code is fast/for each loops) but I have never came across this issue.
    An example .mfa file would be a great way to show the problem.
    - BartekB, a.k.a Uppernate
    Join the Click Converse Discord! - https://discord.gg/7RNXFrC
    Dungeon Raiders! - Link soon™

  5. #5
    Clicker

    Fusion 2.5Android Export Module

    Join Date
    Jan 2007
    Posts
    259
    Mentioned
    5 Post(s)
    Tagged
    1 Thread(s)
    Sorry for the delay. Life is a tad hectic right now . I will see what I can do about providing a MFA. I'll have to change some things up as my current MFA has art in it that I cannot currently share at the request of the artist.

    @mobichan I have tried the always method and the result is the same. As for moving the code around - I have experienced this issue consistently with every enemy I've coded for every project. I code each one from the ground up every time and they're isolated in their own MFAs until they're ready to be dropped into a game.

  6. #6
    Clicker Fusion 2.5 DeveloperiOS Export Module
    butterfingers's Avatar
    Join Date
    Apr 2012
    Location
    London
    Posts
    135
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)
    So, I'm trying to replicate your initial example:
    ScopingTest2.png

    I can run that and get about 5000 actives, all running the loop, and the scoping doesn't seem to break.

    ScopingTest1.jpg

    I've attached the MFA, so you can take a look and let me know if I'm doing something different and not understanding?
    ScopingTest.mfa

  7. #7
    Clicker Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Fusion 2.5+ DLC (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    Diogen's Avatar
    Join Date
    Feb 2016
    Location
    Zaporizhzhya, Ukraine
    Posts
    47
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by butterfingers View Post
    So, I'm trying to replicate your initial example:
    ScopingTest2.png
    In this example, the foreach loop is not needed))))

  8. #8
    Clicker

    Fusion 2.5Android Export Module

    Join Date
    Jan 2007
    Posts
    259
    Mentioned
    5 Post(s)
    Tagged
    1 Thread(s)
    Hiya. Sorry for the delay.

    I actually discovered an issue with my code when removing the assets from it and creating an on/off switch for the fixed value method. One of the events had an object referencing the looped object rather than the other way around so the game was getting confused.

    However. . . .I do still recall having this exact issue with mutliple other complex enemies which is what prompted me to use the fixed value method in the first place. These instances were several years back, though so it would be difficult for me to dig up the code and throw it up here so I will wait until next time and re-post with my issues if they occur again.

Similar Threads

  1. Scoping dont work well
    By hoyoyo80 in forum Fusion 2.5
    Replies: 8
    Last Post: 1st August 2018, 06:36 AM
  2. Question re: Picking Objects / Scoping & Loops
    By Chrille in forum Fusion 2.5
    Replies: 5
    Last Post: 2nd September 2015, 08:22 PM
  3. Before I buy, does iOS exporter work properly?
    By Click_n_Create in forum iOS Export Module 2.5
    Replies: 13
    Last Post: 28th February 2014, 05:47 PM
  4. Does The Big Box object work properly for 64-bit?
    By RGBreality in forum Multimedia Fusion 2 - Technical Support
    Replies: 10
    Last Post: 22nd September 2011, 04:22 PM
  5. Having a hard time properly setting up a Fast Loop
    By RGBreality in forum Multimedia Fusion 2 - Technical Support
    Replies: 10
    Last Post: 17th October 2010, 10:34 PM

Posting Permissions

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