Behavior Request: Loop Reference Update



  • I never use conditional loops, because I can't seem to understand from the documentation how they work.

    There's a conditional, end index, and increment index I think.

    I tried to make it work where 'while startind != endind: dostuff; endind +=1', b I can't seem to get that to work, unless I'm just misunderstanding.

    Would it be possible to update the Refrence and/or behavior to be more clear about what each input does and why? Thanks!

    UPDATE: I need to do stuff after the loop is completed. Unfortunately, I have to build my own way of detecting this. Result is very cluttered and sloppy logic requiring many zero timers.

    Is there any additional possibility of adding detection for when the loop is complete? I apologize again!



  • I don't quite understand your problem, probably because I've never used a conditional loop before, but why do you need to detect after a loop is completed? If you put a behaviour to activate after the loop, it will complete the loop first. As in, you have a behaviour, then underneath that you connect the loop and then next to the loop you connect the behaviour you want to run after the loop.



  • Everything connected to the loop after it is a part of the loop. It doesn't execute unless the loop is running.

    For instance, if a user just moved an object, I need to to it iterate through all compatible objects, and when completed, change a label. Currently I canon,y do that through guessing and timers :/


  • Admin

    What's the issue you're having, and what do you expect to happen?
    You have the correct understanding of all the fields in the conditional for loop.
    The first field is the start index (int i=0 in typical code)
    The second field is the condition ( i != endIndex)
    The third field is the end index
    The fourth field increments i. (i++)

    Your example loop should only do the amount of iterations that are entered in the 3rd field (end index). So if you enter a 10, it will do it 10 times. Is this not happening for you?

    As for the second question, doing things after the loop is completed. There are a few ways of doing this.

    You can do this with a few extra behaviours, and you don't need any timers at all. In fact timers won't do anything while your loop is running, because hyperPad does not run behaviours in parallel. So it will wait until the loop is done before doing the timer. (the loop will freeze your project until it's finished). In most situations, that "freeze" for the loop to finish is not noticeable. When you're dealing with large data sets that's when you notice it. You've probably seen this in other apps when there are long loading times.

    Now for the possible solutions:
    The first one, and the easiest connect a sibling behaviour next to the loop (assuming the loop is connected to a parent behaviour).
    This will trigger your sibling behaviour after the loop is finished.
    In the example below, the sound behaviour will only play once the loop is completely done.
    0_1474919632067_loop.png

    Another option, is to output the index to an IF, and see IF it is >= end index.

    If you're using the For Each option to count tagged objects, then you need 2 loops. One to count how many tagged objects (just output the count for each iteration), and the other to do your main logic you wanted. Then check the count of your second for each loop to see if it matches the total count from the first one.

    Hope this clears some things up.

    We'll post a tutorial on this soon.



  • Okay! That solved my issue, at least in theory. Now, for practice :&

    I guess I just so didn't understand the execution model. Thanks for the detailed explanation!

    The indexes and such could be a little clearer in-editor, however, but I'm not going to nitpick that.


  • Admin

    I agree about making it more clear on the editor side. I think the confusion lies with the fact that the end index is not clearly labeled. We'll play with the UI a bit to make it easier to understand.



  • This post is deleted!