loop + function - weird problem, any ideas?

  • Hey guys.

    I've got some weird problem.

    I've got events like this:

    keyboard "a" pressed : call function "a"

    on call "a":

    for each element of array XY: call function "b" with 3 parameters

    on call "b":

    var = 0

    • add f.call("c",x,y,z) to var
    • add f.call("d",x,y,z) to var
    • add f.call("e",x,y,z) to var
    • var > 0: return 1
    • else: return 0

    "c"

    • for loop 0-8 with one condition: do something + set return value to 1

    "d"

    • for loop 0-8 with one condition: do something + set return value to 1

    "e"

    • for loop 0-8 with one condition: do something + set return value to 1

    The array (bolded part) has 9 elements. So it should call b 9 times, but the game just freezes and I get high cpu usage. Okay, you might say that the problem must be some complication with variables (or similar) when calling the function b more than once in a loop.

    BUT here is the weird thing: it runs fine if I use "for 1 till 9" as loop. Why could that happen?

    I would prefer using the array: for each element XY as it would be more elegant(as I have to iterate over two dimensions). So maybe someone got much experience with loops in loops and has already experienced this and found out why this happens?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)