I have a function to modify an array, if I comment out the .pop() line, it passes, if not, I get this error:
VM error.revert
Code:
function moveShipsToSpace(uint[] memory ships, uint16 fromSpace, uint16 toSpace) public{
for(uint8 i= 0; i<ships.length; i++) {
require(containsInSpace(ships[i],fromSpace), "dont have that ship");
// Move the last element into the place to delete
whichShipsAtSpace[msg.sender][fromSpace][i] = whichShipsAtSpace[msg.sender][fromSpace][whichShipsAtSpace[msg.sender][fromSpace].length - 1];
// Delete
whichShipsAtSpace[msg.sender][fromSpace].pop();
// Insert in new location
whichShipsAtSpace[msg.sender][toSpace].push(shipsArray(ships[i]));
emit LogUint(ships[i]);
}
}
Also, if I pass a single number, it passes with .pop(), if I pass 2 or more it fails, so not sure what is the issue, please halp!