Triple nested foreach doesn't work

Welcome to our brand new Clickteam Community Hub! We hope you will enjoy using the new features, which we will be further expanding in the coming months.

A few features including Passport are unavailable initially whilst we monitor stability of the new platform, we hope to bring these online very soon. Small issues will crop up following the import from our old system, including some message formatting, translation accuracy and other things.

Thank you for your patience whilst we've worked on this and we look forward to more exciting community developments soon!

Clickteam.
  • I'm making a game where a line is drawn between two moving objects. I want to make multiple instances of this setup that are created during gameplay, so I'm saving an "id" for each object and having the line (which is a 1x1px object) connect between the start and end objects by using three foreach loops:

    1. For every line object, start a loop on the start objects
    2. For every start object, if it has the same id as the line object, start a loop on the end objects
    3. For every end object, if it has the same id as the line object, position the line on the start object and connect it between that and the end object (using scale and rotation.

    It works perfectly fine with just one setup, but once I add another one with a different id, the line from the first setup connects to the end object from the second setup... even though I can confirm with the debugger that they have different IDs. If I add a check on the third loop to make sure the start object has the same id as the line, then both lines end up following the newly created setup.

    I also tried having the loop begin with the start and end objects instead, but doing that caused the first line to stop connecting once the second setup was created.

    I've attached an example of the code. Please let me know if I did something wrong or if Fusion just doesn't support foreach like this... if so, is there a better way of doing what I'm trying to do?

    Please login to see this attachment.

  • Nevermind, I found a solution! Turns out I was massively overthinking it and don't need to loop the start and end objects at all. All I need to do is just run a foreach on the line object, then have two conditions check if the id of a start and end object matches the id of the line:

    I'm pretty sure that nested foreach loops work though, at least with two objects, so I hesitate to call it "the" solution rather than "a", I don't know if anybody has anything else to add, but if anybody in the future encounters a similar problem, try letting Fusion handle it?

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!