One more question here, sorry this lesson’s got me a bit confused. Thi is Filip’s exact code, copied code directly from the github into my Remix.
I am referring to the array_w_unique_ids.sol file. I am having errors compiling it and I believe it is the return entityStructs.push(newEntity) -1; line that is the issue. The error says "operator - not compatible with types tuple() and int _const 1 and it says “different number of arguments in return statement than return declaration” .
Can anyone explain this and the fix for it? I am confused anyway because the header has return (uint rowNumber) and the body we return (newEntity)-1 ?!?! That doesn’t seem consistent. Thanks in advance for the feedback.
pragma solidity 0.8.0;
contract arrayWithUniqueIds {
struct EntityStruct {
address entityAddress;
uint entityData;
}
EntityStruct[] public entityStructs;
mapping(address => bool) knownEntity;
function newEntity(address entityAddress, uint entityData) public returns(uint rowNumber) {
if(isEntity(entityAddress)) revert();
EntityStruct memory newEntity;
newEntity.entityAddress = entityAddress;
newEntity.entityData = entityData;
knownEntity[entityAddress] = true;
return entityStructs.push(newEntity) - 1;
}
function updateEntity(uint rowNumber, address entityAddress, uint entityData) public returns(bool success) {
if(!isEntity(entityAddress)) revert();
if(entityStructs[rowNumber].entityAddress != entityAddress) revert();
entityStructs[rowNumber].entityData = entityData;
return true;
}
function isEntity(address entityAddress) public view returns(bool isIndeed) {
return knownEntity[entityAddress];
}
function getEntityCount() public view returns(uint entityCount) {
return entityStructs.length;
}
}