Stop Loop doesn't work on a For Each Array Element loop

0 favourites
  • 2 posts
From the Asset Store
🙌 Element Magic Hit Sound Pack comes with 805 high-quality sound effect
  • Problem Description

    Attempting to Stop Loop on a For each element loop on an array, but it continues the rest of the loop.

    Attach a Capx

    drive.google.com/file/d/0B7Gu37yDX14xdTIyc1p1VnJjYjQ/view

    Description of Capx

    I've made a simple array with a list of Thingees and a Weight for each. I'm trying to randomly pick one based on the weights. (In my example the weights are all identical.) When you click the GO button, it loops through all the weights and adds them up to get the total, then picks a random number between 0 and that total. Then it loops back through the array and subtracts each weight from the random number until the number is negative. If it is, the loop should stop and return the Thingee associated with the current weight's row.

    (Note: I think I've found a work-around that is probably a better way to achieve my goal, but this still seemed like a bug. Also, I know selecting things with weights is a common programming problem and I don't claim to be an expert, so there might be a much better approach. I wouldn't mind advice on optimizing my approach if it comes to mind when reviewing my code.)

    Steps to Reproduce Bug

    • Click the button and view the output.
    • If the random number picked is greater than 20, then the loop will stop properly on the last item. If this happens, click GO again to retry.
    • When the random number is low enough that the loop should stop on the first or second item (because it becomes negative), the loop is supposed to stop. The text display will say "Stop Loop!"

    Observed Result

    Even if a Stop Loop action is fired early in the loop, the loop will continue through all three elements.

    Expected Result

    When the random number is decremented below zero, and the Stop Loop action is fired, I expect that the rest of the actions in the set will fire, but the loop will not continue to the next element.

    Affected Browsers

    Tested on Chrome

    Operating System and Service Pack

    Windows Vista (latest service pack)

    Construct 2 Version ID

    Release 200, 32-bit, Steam version

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • It's not a bug, the System 'Stop loop' action is only designed to work with System loops. Perhaps you could iterate the array using a system loop.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)