Strugling with array…

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

    I'm still trying to use array for different things each time and here is my new issue.

    I have to beautiful table.json that is actually displayed in an array.

    I also have a corresponding instance that is one of the values in the column 0,2,4 and 6.

    My objective is the check in my array, in the column 0 for example, the corresponding value. And then, getting the value from the column 1, same row.

    (As this for more clarity:)

    So I'm dealing with this code to get it done:

    + Array: For each X element
    + Array: Value at Array.At(0,Array.CurY) = MyVariable
    -> Text: Set text to Array.At(1,Array.CurY)
    

    But of course it's not working…

    I think the problem is with this line

    + Array: Value at Array.At(0,Array.CurY) = MyVariable

    but I really don't know how to deal with it.

    Also, maybe my method with this is not the good one. I thought using array was the simplest thing to do…

  • When you go for each x (row) then you are looking for a curX not a curY. CurY would be the same like 0 or undefined. So almost there, if you are iterating each row then you want array.at(array.curx,0) and array.at(array.curx,1) in those events.

  • I already tried this, but my text is still unchanged.

  • You'll have to debug it then. There's loads to consider. Did the file get imported into the array correctly and before this event was run? Check the array in the debug menu. Is it failing because the variable is in a wrong format or just incorrect value? Use the Browser log action to print out some things during the event to see what it's finding in the array and if it's expected.

  • Looks like you have always 1 column where you store the value to check and right after on the second column the UIDs:

    0-1

    2-3

    4-5

    6-7

    If you are sure that the columns that store the UIDs they never gonna much with the variable that you are checking on your first columns as it will mess up things with wrong flags, because you are looping through all the columns, then you can do:

    You didn't say if you need to loop through all the Raws swell?

    Assuming that you need to check the whole Array (Columns & Raws)

    + Array: For each XY element

    Array: Value at Array.At(Array.curX,Array.CurY) = MyVariable

    -> Text: Set text to Array.At(Array.curX+1,Array.CurY)

    But if you think that the UIDs can match the Variable that you are checking then is better to loop just through the columns you need:

    0,2,4,6

  • Yes, I'm pretty sure that my table is well imported in the array:

    I did also tried to disable the second event, just to check:

    + Array: For each XY element
    + [DISABLED] Array: Value at (Array.At(Array.CurX), Array.At(Array.CurX)) = Variable1
    -> Text: Set text to Array.At(1,Array.CurY)
    

    It only display "D", the last cell of the column 1.

    So I can say that it's supposed to work, bu it doesn't.

  • It only display "D", the last cell of the column 1.

    So I can say that it's supposed to work, bu it doesn't.

    What are you trying to do? why didn't work? what are you expecting to happen on your last example?

    According to your last events it works as intended.

    You loop through the whole Array (Columns & Raws) but you just printing on the text:

    Column = 1

    Current Y

    So the last Y on (Column1 = D)

    You just printed the Raws in Column1 ober and over.

    You can loop through just one column without looping through the whole Array.

  • My last example was just to check that there is no problem importing a value, sorry I'm just a beginner with the arrays.

    But my purpose, as you noticed earlier, is to match my variable with the value of the first column and then pick the value on the next column.

  • My last example was just to check that there is no problem importing a value, sorry I'm just a beginner with the arrays.

    But my purpose, as you noticed earlier, is to match my variable with the value of the first column and then pick the value on the next column.

    No worries)

    The easiest way to resolve this so you can see how everything works is by you give a specific example, as your question is a bit too broad:

    Example:

    1-Are you trying to check all the columns and Raws?

    2-Or are you trying to check just one column?

    3-What happens when you find a matching one do you stop the loop? or do you continue checking the rest of the column?

    You see? according to what you need the answer will be different.

    Also, just a quick note, if you trying to print on the text multiple UIDs or vales then you need to use:

    set Text to -----------Self.Text & newline & NewValue

    To Check the first column for example without stopping if there is a match:

    For "Y" from 0 to (Array.Height-1)

    ----Array: Value at Array.At(0,Loopindex(("Y")) = MyVariable

    --------> Set Text to: Self.Text & newline & Array.At(1,Loopindex(("Y"))

  • Ok sorry, I get it. So let me explain exactly how I want it to be:

    • First I have a variable for column 1, I need to check in my array at column 1 where is the matching value (For example if my variable is 1|0|0, I want it to check where in my column the same value is. I only need to check the 1 column because that’s my variable for it).

    • When the value match, it stops the loop and picks the value on the second column (if my value is located in the cell x3, y0 I want it to pick the value in cell x3,y1)

    • Then I get this second value that I want to display in the text bloc.

    I though that this method with array is the easiest way to do what I want but maybe I'm wrong and there is something more simple?

  • • First I have a variable for column 1, I need to check in my array at column 1 where is the matching value

    • When the value match, it stops the loop and picks the value on the second column (if my value is located in the cell x3, y0 I want it to pick the value in cell x3,y1)

    From your explanation, It seems that you have the (Columns & Raws) inverted, maybe that's why you have many issues.

    First Column is (X = 0) not (X =3)

    So if you find a match you will pick up the value from (X = 1)

    You can still use my last example:

    To Check the first column for example without stopping if there is a match:

    For "Y" from 0 to (Array.Height-1)

    ----Array: Value at Array.At(0,Loopindex(("Y")) = MyVariable

    --------> Set Text to: Self.Text & newline & Array.At(1,Loopindex(("Y"))

    You just have to add one more action after you set the text

    "Stop Loop"

    I though that this method with array is the easiest way to do what I want but maybe I'm wrong and there is something more simple?

    It's very simple once you learn how to do it and it's the correct way of doing it.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Maybe it's time to share the file?

  • Maybe it's time to share the file?

    Yep definitely the time because I can't make it works. Here is my file:

    dropbox.com/s/otrysy1ehg3cvdh/ArrayTest.c3p

    But I was also thinking that maybe I did my table the wrong way. I can make it more simple as the values I'm searching are the same for the columns 0,2,4 and 6.

    I can probably put my values (the ones identical as my Variable) on the first row and all my seconds values (the ones I want to display in the text bloc) in the 4 next rows like this:

    More easier. (Btw, is it ok to rename the Y column as I did?)

  • I agree, that was a good idea to show your project as they were many issues, otherways we would have lasted a while with this back and forwards from what I see you was going on a different direction))

    I modified your Project:

    https://www.dropbox.com/s/qbjybup1y0lj7py/ArrayTest2.c3p?dl=0

    1-Use (Compare at XY) instead of (contains a value)

    2-For the Loop you need to put the Actual Array Height size, not the Value.

    3-In your Goblal variable "Variable1" you entered the wrong value:

    1|0|1

    Because there is one character missing at the end as in your Array you have:

    1|0|1|

    So it will never trigger the match, make sure you always put the exact value.

    4-If you dont need to check the Array every tick make sure you put this code under a trigger or a function so you can call it only once, as how it is now is running every tick.

  • Oh great! Thank you! I just realise my main mistake, even when I tried to reproduce it, was this:

    3-In your Goblal variable "Variable1" you entered the wrong value:

    1|0|1

    Because there is one character missing at the end as in your Array you have:

    1|0|1|

    So it will never trigger the match, make sure you always put the exact value.

    I couldn't figure it out without you.

    Thank you so very much!!

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