How do I do something in a For Loop only if True?

0 favourites
  • 2 posts
From the Asset Store
For Adventure, Action, Heroes, Sci-fi and Action-RPG games.
  • I'm uncertain how to write this in Construct 2. I'm attempting to assess a 2D array. One column is a value name for a location check while the other is a boolean switch. I'm trying to run through the array and if the switch is true, append the name value of the boolean to a text variable. Here's what I got:

    Array proximity

    Sprite player

    Local text string = ""

    Local number i = 0

    For "" from 0 to proximity.Width, add 1 to i

    -->proximity Value at (i,1) = 1, Set String & proximity.At(i,0)

    If i >= proximity.Width, then set player.proximity to string

    Some sample values within the array:

    Wall,1

    Floor,1

    Ceiling,0

    Ledge,0

    Expected output: player.proximity=WallFloor

    I can append the string if I have everything on the for loop and get every name value, but I can't seem to figure out how to add conditions within it to just get name values that are true.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Ha, okay. I'm just an idiot. That IS the right code. On start of layout without any user input, all switches were set to 0, hence no output. It's amazing what sleep and fresh eyes can do.

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