BitGuildPlatform / Contracts

Various BitGuild public contracts
4 stars 2 forks source link

Manually update the length after deleting item from the array #12

Closed pauliax closed 6 years ago

pauliax commented 6 years ago

AvatarItemToken.sol

    avatarItems[tokenIndex] = avatarItems[avatarItems.length.sub(1)];
    delete avatarItems[avatarItems.length.sub(1)];

Now the length of the array is not reduced, just the last element becomes empty. To fully remove an item you need to manually update the length property: avatarItems.length--;

shaokun11 commented 6 years ago

@pauliax Thanks your opinions. At this version, I use the avatarItems.length to generate token id , if I really reduce the length, which will cause duplicate token id. so I just swap burned item position for last item position.