Vous n'êtes pas identifié(e). Pour pouvoir écrire ou répondre à un message, vous devez vous connecter ou vous créer un compte sur JAWA.
Pages : 1
How can I compare two arrays?
I have tried some syntaxes, but these seem not to work..
I tried
array1$1$1=={{array2$1$0}}
And
array1$1$1={{array2$1$0}}
And
array1$1$1==array2$1$0
And
array1$1$1=array2$1$0
Now I am trying to colpare all elements in my arrays. Is it also possible to compare two arrays alltogether? Like
array1 = {{array2}}
Hors ligne
Hi Martijn Spook !
About the syntax :
- you need to add the {{ }} on the right side of conditions, otherwise you'll compare array1 value to the literal string "array2". Values on the left side always stands for variables so you can and the {{ }} but it's not mandatory.
- the equality operator is just " =" , not "=="
So :
- to compare specific cells values the good syntax is:
array1$1$1={{array2$1$0}}
BUT, the was a bug on this case (array cell to array cell comparison) which is FIXED now *
- to compare full arrays :
array1={{array2}}
is the right syntax BUT you need to remove spaces around the "=" because spaces are included in the literal values on the right size of comparison.
* Arrays variables is a new feature in JAWA 32 with lot of implications in the engine so their may be other bugs or missing cases like this. Please post any bug or potential bug in this room if it occurs again.
Z
I added
Thanks for the elaborate answer.
The way I have set uip my tyestgame mnow, I need to compare two rows of an array.
Woudl it be possible to do something like:
array1$*$1={{array2$*$0}}
to compare the whole first row tot the whole second row?
Hors ligne
hello Martijn
Sadly there's no syntax to extract and compare a specific row or column from an array. I'll think about it for the next version (could be an interesting feature) but in the meantime you'll need to compare each cell of the row or split the 2D array in 1D arrays.
Z
Ok now you can compare rows or columns of array using the char "*", meaning "all cells", instead of a cell or column coordinate. To be a bit more clear :
ARRAY$*$2 = all cells from line 2 = line 2
ARRAY$4$* = all cells from column 2 = column 2
Wow. I just noticed the feature now.
Great!
little remark: I suppose the last line must be:
ARRAY$4$* = all cells from column 4 = column 4
Hors ligne
yes, my mistake !
Pages : 1