Is there a way to make a fastloop like this?

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.
  • Hi!

    Stupid question I'm sure but I know fastloops start from 1 and go to whatever you specific (ex run loop 32 times).

    My question is can you have it start from a number other than 1? Like in the old days if I wanted a loop to run from 5 to 15 I could just write For X = 5 to 15.

    I don't want to make all the conditions (fastloop index +5) because I'd have to change a lot, so was hoping I could just change the numbers in that initial fastloop instead.

    Thank you for your help!

    Weebish Mines, my retro Metroidvania!
    Please login to see this link.

  • I think if you set an event that says LoopIndex("YourLoop") is greater than 4, you would get what you want.

    Please login to see this link.
    Please login to see this link.|Please login to see this link.|Please login to see this link.

  • Don't think there's a way around having to add 2 additional conditions (using 'compare 2 general values') to the 'on loop' trigger to keep the value clamped to within that range. There is an action to set the loop index as defisym says, but you still need to waste at least 1 loop to check for it & you still need the additional conditions. It's also pretty slow which may or may not be an issue, depending on your use-case.

  • Like I said, you don't need conditions, the whole point you want to skip some indexes is so loopindex returns something in between 5 and 15 for example, right?
    So if you're using loopindex for something you can just use loopindex + start number...
    If you're not using loopindex anywhere, then what's the point of having loopindex starting in a different number?

    So here's a example showing two uses: Selecting object from one ID using a loopindex+offset and the other is adding to a list (or any setting any value) with loopindex+offset, which doesn't require any extra condition.
    Please login to see this attachment.

    If you have too many conditions or expressions to change, you'll have to deal with it and replace it, doing dirty workarounds will cause problems afterwards...
    But if you really want to workaround this, setting the loopindex won't cause any delay whatsoever, cause a loop will start and finish before going to the next normal event or even action if it was called in between those.
    It won't cause any delay, it won't cause any performance issue, it's actually lighter than using a condition cause it doesn't have to check multiple times for something.

    Edited once, last by NaitorStudios (October 22, 2021 at 3:14 PM).

  • Im doing some crude experiments with the 'set loopindex' action, and I can't envisage a scenario where you're able to only use that action and still keep the values scoped within that range. In fact it seems to really add nothing at all.

    If you set koopindex to 5 after you start the loop, how are you able to keep track of what iteration it's on without another condition in your on loop event?

    Something else I discovered however, is that trying to set loopindex from inside the same fastloop (as in on an "on loop" event), will actually crash Clickteam Fusion.

    If anything, it's probably better to just not use set loopindex at all & stick with the more stable additional conditions method.

  • I did also try to see if I could gauge it's performance using the microtimer object to see if it was as slow as I thought I remembered it being, but it turns out in my limited experiments that it made no difference one way or the other. Setting the fastloop index to 5 was no faster or slower than just waiting for the fastloop to reach 5 iterations & using an on loop event + conditions to scope it.

    For the record, my "test" basically consisted of running a loop 32 times & creating objects when the loopindex was between 5-15, and seeing how long the loop took to reach its endpoint, trying to see if there was any performance difference if you set the loop index to 5 or not (which there wasn't), so far from an exhaustive test. The crash is legitimate, though.

  • Something else I discovered however, is that trying to set loopindex from inside the same fastloop (as in on an "on loop" event), will actually crash Clickteam Fusion.

    Of course it will crash, if you continuously set it to a specific index it will never finish, meaning it will be a infinite loop, causing the crash.
    If you just use a "only one action when event loops" condition it won't crash. In fact, you can't change the loopindex from outside the loop. Cause the loop would start and finish before the action ever runs.

  • In fact, you can't change the loopindex from outside the loop. Cause the loop would start and finish before the action ever runs.

    That's kind of true, but not entirely:

    Please login to see this picture.

    In a sense, you're right, because we're still technically inside the "fred" loop when we change the loopindex...but only indirectly. We're directly inside the "barney" loop, yet we can meaningfully change the loopindex of "fred" from there. We can see it worked because "fred" was originally supposed to create 10 (x2) shapes, but only created 5 (x2).

    Please login to see this link.
    My Fusion Tools: Please login to see this link. | Please login to see this link. | Please login to see this link.

  • Of course it will crash, if you continuously set it to a specific index it will never finish.


    Ok, I think that's probably what I missed X)

    But actually, you can set the loopindex if you do it on a single iteration from within the same loop, and Fusion won't crash.

    But like I said before, you still have to use up a loop to do the check & at least one condition to scope the loop step.

    At that point you might as well just use conditions, seeing as it wouldn't take much of a miscalculation to crash fusion with set loopindex.

  • Conditions means it would need to compare values on every single instance of the loop, while setting loopindex would skip this entirely. So it would be effectively doing more work.
    Here's a simple example, although the performance difference might not be much on a small loop called once, it will stack up with other events and can become a problem later on.
    So setting the loopindex is a better approach.

    Please login to see this picture.

  • Conditions means it would need to compare values on every single instance of the loop, while setting loopindex would skip this entirely. So it would be effectively doing more work.
    Here's a simple example, although the performance difference might not be much on a small loop called once, it will stack up with other events and can become a problem later on.
    So setting the loopindex is a better approach.

    Please login to see this picture.

    Thanks a lot! I did something like this and it appears to work perfectly.
    What I’m trying to accomplish is boost the performance of my roguelike by reducing the amount of map tiles it has to check in order to move monsters around. It went from checking a 32 x 32 grid to a (player Y-5, player X-5) to (player Y+5, player X+5) section and it’s speeding things up a bunch.

    Weebish Mines, my retro Metroidvania!
    Please login to see this link.

Participate now!

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