How do I use OR inside a WHILE loop?

  • Hi,

    for checking if the next random position of an object is "free" for placing on the map, I want to randomize these until a space is found.

    Anyway, I got multiple objects which should not be "in the way".

    So, I want to use OR conditions inside the while-Loop to check if the new position is overlapping any of these objects - without Families, Containers or another background.

    This question was asked before, but not answered.

    Could you help me? Thanks!

  • Add a local variable "b".

    Change your loop to this: "While b=0"

    Inside the loop generate random X and Y, do your overlapping checks and when the suitable position is found, set b=1

    I also advise to add another condition to the While loop: loopindex<100

    This is to prevent infinite loop in case there is no free space left on the map.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Maybe an upgrade for the while function of c2, but this workaround does its job.

    Thank you!

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