0 Favourites

BUG:Nested loopindexes with the same loopindex variables

  • Problem Description

    If you nest loops and use the same loopindex, even if it is in a seperate function, it does not work correctly. In the example below, replacing the second "a" with a "c" causes it to loop four times rather than eight. This can be problematical if writing effective code functions in C2 - discovered this when I had nested loops with "xi", but the two loops with index "xi" were in completely different files.

    Attach a Capx

    Description of Capx

    Three nested loops with duplicate loopindexes (loopindices ?)

    Steps to Reproduce Bug

    • Step 1 : Run the above code

    Observed Result

    1,11,0

    1,12,0

    2,11,0

    2,12,0

    (from Browser log window)

    Expected Result

    Should be 8 outputs not 4. Or should warn about reusage. I'm hazarding a guess that loopindex is stored in a java hash in the runtime ? Maybe the loopindex value could be set to nil when the loop exits and if there is a loopindex already present when a loop is started causes a RTX ?

    Affected Browsers

    • Chrome: (YES)

    Operating System and Service Pack

    Windows 10

    Construct 2 Version ID

    v206 64 bit

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Thanks, good catch. Should be fixed in the next build. Note for me it did loop the correct number of times; it is just that the Chrome dev tools log would collapse identical logs in to one line with a number next to it. The issue was loopindex("a") was returning the least nested loop's index (event 2) rather than the most nested (event 4). From the next build, when identical loop names are used it returns the most nested first, which fixes it.

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