User Tag List

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 15

Thread: I'm trying to figure out the "for each" loop, Please help.

  1. #1
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleSWF Export Module
    Disthron's Avatar
    Join Date
    Sep 2007
    Posts
    244
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Exclamation I'm trying to figure out the "for each" loop, Please help.

    Hi everyone,

    I'm trying to understand the "for each" action and the "on each object" condition and how they work. I couldn't find anything on them in the help files. Are they related to one and other?

    I thought it was a case where the "for each" action started a loop and the "on each object" was where the events went. But I have 2 events in the loop and I can't seem to get it to work properly. I'm using it on a group, dose that make a difference?

    I'm making a semi-isometric game and I want to give all the buildings a "shadow" object with the same ID. So that the "shadow" object can be used for collision detection and when the building is destroyed it's "shadow" is destroyed too. So there are no invisible walls left behind.

    I have 2 different objects in the group, I spread 0 through the Alterable Value A (witch I named ID) of the group. Then, in the loop I check to see if another veriable is set to 1 or 2. It creates the "Shadow" object but it doesn't set the ID to the ID of the main object. It instead sets it to the last ID of the other set of objects.

    I hope that explanation makes sense, thanks for reading this fare. Any help would be greatly appreciated.

  2. #2
    Clicker Fusion 2.5Android Export ModuleSWF Export Module
    Ziplock's Avatar
    Join Date
    Oct 2013
    Posts
    448
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Seems like you're trying to apply a slightly older way of doing things and mixing it up with For Each. Used to be there was no For Each, and you would need to Spread Value via FastLoops to give your instances individual IDs. You would do this with different objects to make matching IDs, then pair them. This still works, but For Each, once an extension, is now stock with Fusion, so this technique is a little deprecated.

    For Each is a FastLoop that runs a number of times as the number of instances of that object that you have, and also will only apply actions to each instance one at a time during the loop.

    If I'm understanding, you might want to try "For Each of Two Objects," which will essentially make parent and child objects. You would want to make a shadow every time a building is built, pair the shadows with the buildings, and destroy them when the building is destroyed.


    Number of "Shadow" objects < NObjects "Buildings"
    -> Create "Shadow" at (0,0)

    Always
    -> "Building" - For Each of Two Objects - "Shadow", Loop Name "ID"

    On Each One of "Building", Loop Name "ID"
    + On Each One of "Shadow", Loop Name "ID"
    -> Set "Shadow" Position at (0,0), Relative to "Building"

    On Each One of "Building", Loop Name "ID"
    + On Each One of "Shadow", Loop Name "ID"
    + however "Building" is destroyed
    -> Destroy "Building"
    -> Destroy "Shadow"

  3. #3
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleSWF Export Module
    Disthron's Avatar
    Join Date
    Sep 2007
    Posts
    244
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hmm... I was trying to go through every building that has been created, create a Shadow for it, and then assign the ID of the building to the the shadow that was just created.

    Anyway, thanks a lot for your advice. I'll try the way you suggest tomorrow.

    I'm still a little confused though. How dose the program know witch shadow is connected to witch building, and wouldn't having a fast loop activate on "Always" cause slowdown? Or is that not a problem? I feel like the pairing shouldn't be checked accept at the start of frame and when a building is destroyed but maybe I'm just being paranoid.

  4. #4
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleSWF Export Module
    happygreenfrog's Avatar
    Join Date
    May 2011
    Location
    I.L.T.D.O.I.R (I.L.T.D.O.I.R's Location: The Dimension Of Infinite Recursion)
    Posts
    4,307
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Well, if you want to attach an ID to the shadows, why not just attach the fixed value of each building object to them instead of an alterable value?

  5. #5
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleSWF Export Module
    Disthron's Avatar
    Join Date
    Sep 2007
    Posts
    244
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I don't really understand the fixed value ether.

  6. #6
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleSWF Export Module
    Disthron's Avatar
    Join Date
    Sep 2007
    Posts
    244
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Ok, I'm using two groups, there are 2 objects in each group. There is a small building, with a corresponding shadow, and a large building with a shadow as well. I'm also testing a variable (Alt Ver B "Size") to see witch type of shadow should be created.

    I'm getting this strange occurrence where the loop will run though the first set of Buildings just fine, but when it goes to the next it keeps setting the ID to the loop index of the last of the first set of Buildings. Here is the code I'm using. Mouse over the buildings and the shadows to display there IDs.

    I feel like this should work.

    https://dl.dropboxusercontent.com/u/...estThingy3.rar

  7. #7
    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)
    Here is an ForEach Loop Child -> Parent example,
    It uses Fixed Values, ForEach loops and such

    ForEach Child To Parent Example.mfa
    In this example creating child object is also dynamic, so whenever a new parent object is created, child objects are created too.

    Also, do not worry about slowdown, one for each loop will do nothing unless you use it constantly on a lot of objects (e.g. checking distances between all instances of enemies and allies, about 30 enemies and 30 allies began lagging (900 foreach loops + 900 distance checks, boy))
    I currently use around 5 For Each loops for different objects right now with "Always" as the event.

    As for your "I'm also testing a variable (Alt Ver B "Size") to see witch type of shadow should be created."
    you can use the "Create object by name" action in the built in Create object and use the expression [ "shadow_"+str$(Alterable Value "Shadow_Type") ] and name your shadows accordingly.
    - BartekB, a.k.a Uppernate
    Join the Click Converse Discord! - https://discord.gg/7RNXFrC
    Dungeon Raiders! - Link soon™

  8. #8
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleSWF Export Module
    Disthron's Avatar
    Join Date
    Sep 2007
    Posts
    244
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi PMBartekB

    Your example really helped, thanks a lot. I decided that the shadows didn't need to be different objects and I could instead just change there direction to make them match up. I'm also using a group for the main "big face" objects. So if you add more it should still work. Check out my edit to see what I mean.
    Attachment 19374

    Thanks to everyone for there help. ^_^

  9. #9
    Clicker

    Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleUniversal Windows Platform Export ModuleSWF Export ModuleXNA Export ModuleInstall Creator Pro
    nivram's Avatar
    Join Date
    Jul 2006
    Location
    Bandon, Oregon
    Posts
    6,729
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)
    Invalid attachment is shown when I click on your link.

    Thanks,
    Marv
    ​458 TGF to CTF 2.5+ Examples and games
    http://www.castles-of-britain.com/mmf2examples.htm

  10. #10
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleSWF Export Module
    Disthron's Avatar
    Join Date
    Sep 2007
    Posts
    244
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hay Marv,

    Sorry about the late reply. Here is my edit of the example from PMBartekB. I uploaded it to my dropbox. It allows you to create a child object, link it to the parent and then change the direction based on variables in the parent. Witch makes it match the parents color. You could probably take it a step further and spawn different objects from the child. But I didn't need to for my purposes. I hope that makes sense. But PMBartekB had nicely commented everything.

    https://dl.dropboxusercontent.com/u/...GroupSpawn.rar

Page 1 of 2 1 2 LastLast

Similar Threads

  1. Replies: 6
    Last Post: 18th August 2015, 02:23 AM
  2. question about "odd" ForEach loop behaviour
    By Jorum in forum Fusion 2.5
    Replies: 5
    Last Post: 12th August 2014, 10:25 PM
  3. Looping sound? Stops after first "loop"
    By Outcast in forum HTML5 Export Module 2.5
    Replies: 7
    Last Post: 27th January 2014, 04:59 PM
  4. "Caret" problems with the Rich Edit Object/Fast Loop Question
    By Gullyking in forum Multimedia Fusion 2 - Technical Support
    Replies: 0
    Last Post: 4th June 2012, 04:41 AM
  5. Start loop "loop" 'Alterable Value A' times
    By Dynamite in forum Multimedia Fusion 2 - Technical Support
    Replies: 5
    Last Post: 9th May 2009, 07:26 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
  •