How do I find the x(row) in array where value = x?

0 favourites
  • 3 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • Hello all,

    I have searched for this and read the manual but for some reason my code isn't working. I am just trying to find out the x (row) of the array where a value occurs in a certain column (I know the y). I don't have to worry about repeats. Am I doing something wrong??

    Here is my code which I took a screen-shot of because the project itself is huge.

    Basically I am looking for 2 values one is "mal_code" and the other "fem_code" in the first column of the array and am trying to get the x(row) where they occur loaded into the variables "mal_row" and "fem_row"

    Thanks for looking it over and for any advice you might have.

    Kate

    Tagged:

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The Picture shows that you are looping through a 2D Array using the "For Each XY" but in the Conditions, you are just checking the First Raw (Y = 0)

    You will need to change both conditions:

    Value at (Self.CurX, Self.CurY) = fem_code
    Else: Value at (Self.CurX, Self.CurY) = mal_code
    

    Though you say you need to know the "Raw" but to get the Raw you need to target the "Y" not the "X"

    Basically I am looking for 2 values one is "mal_code" and the other "fem_code" in the first column

    The same thing I explained above if you need to check just the First Column you need to target (X = 0)

    Value at (0, Self.CurY) = fem_code
    Else: Value at (0, Self.CurY) = mal_code
    

    That will target just the first column though instead of looping the whole Array just to check the first column unnecessary you can just use the "For" Loop and check directly the first column. If you have a small Array then is ok you can still use your method if it's easier but if it's big then I recommend you to use the "For" Loop.

    Example:

    For "Y"
    
    From 0 To Array.Height-1
    
    Value at (0, LoopIndex("Y") = fem_code --------- Set fem_code = LoopIndex("Y")
    Else: Value at (0, LoopIndex("Y")) = mal_code ------ Set mal_code = LoopIndex("Y")
    

    This will check just the First Column

  • Tarek,

    Thank you so much! You are correct I am getting my Xs & Ys crossed. For some reason I find them a bit confusing. I keep wanting to make the rows into x because they run right to left but x actually denotes the columns. That should definitely set me straight.

    I will also try to implement the for loop to save on computing power. I just thought that if it was a 2D array then I had to use For Each.

    Thanks again for the help.

    Kate

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