Ideas on shortening long array based conditions

0 favourites
  • 3 posts
From the Asset Store
Full game Construct 2 and Construct 3 to post on Google Play
  • say there is an event that must compare values on multiple array cells in say a 5 x 5 area in a for each X&Y loop.

    for example, if I wanted to compare all cells in a 5 x 5 area to be equal to 0. The first thing that comes to mind is:

    for each XY element:

    compare at XY X: array.curX Y: array.curY Value = 0

    compare at XY X: array.curX + 1 Y: array.curY Value = 0

    compare at XY X: array.curX + 2 Y: array.curY Value = 0

    compare at XY X: array.curX + 3 Y: array.curY Value = 0

    compare at XY X: array.curX + 4 Y: array.curY Value = 0

    compare at XY X: array.curX Y: array.curY + 1 Value = 0

    compare at XY X: array.curX + 1 Y: array.curY + 1 Value = 0

    ... & so on until compare at XY X: array.curX + 4 Y: array.curY + 4 Value = 0

    -----> [action]

    this would work, but it's awfully spacious. Any thoughts on applying some form of math or technique to shorten this but still be able to check all 25 conditions?

    Hope this was clear enough, much appreciated.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Loop through every value, add it to a variable. If the variable is not 0 in the end, then they were not all 0.

    Edit/ I think I misunderstood. Try

    | Global number Variable1? = 0

    + Array: For each XY element

    + System: Variable1 = Array.CurX = Variable1+5

    + System: Variable1 = Array.CurY = Variable1+5

    -> (no actions)

  • this looks good. thanks for the reply.

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