I am trying to assign the value of a matriz to two arrays as follows:
pragma solidity ^0.4.24;
pragma experimental ABIEncoderV2;
contract ArrayExamples {
int[][] public matriz;
// Os dados são recebidos da seguinte forma: [0,0]
function receive_data(int[] data) public {
matriz.push(data);
}
function teste() public returns (int[] v) {
int[] x;
int[] y;
uint t = matriz.length;
for(uint i = 0; i < t; i++) {
x[i] = matriz[i][0];
y[i] = matriz[i][1];
}
return x;
}
}
The array is dynamic, but in the example above defaults to an array with two elements. [0.0]
When I assign the values of x and y in for, only the values of y are assigned correctly. x is responsible for taking only the first value from the dynamic array of the matrix and y takes the last value.
When I check the value of x, it appears that he took the last value from the dynamic array, and he should get the first value from the array.
If I enter the following array: [4,5] - both x and y get 5, where x should get 4.