1
address[] public players;
mapping(address => bool) private activePlayers;

I want to avoid duplicate players to enter in players array, so i want to understand if i create a such mapping with address pointing to bool. and once the game is over can i loop through the mapping and reset it ? is it even possible to reset the mapping. Is there any other efficient way to check if an address exists in an array like players?

1 Answers1

1

You need another private or internal function that returns(bool isPresent) and have the other function run it before adding the address.

"Resetting" a mapping is possible, but it's more viable to just create an array of mappings and have it iterate whenever you go to a new round to avoid that cost altogether.

ctnava
  • 94
  • 5