Mappings
Check out the following syntax:
mapping (uint => address) public punkIndexToAddress;
This is a special kind of data structure: punkIndexToAddress
points to something not unlike an Excel table with two columns. The first column refers to the punk identifier between 0 and 9,999; and the second column contains the address of the owner of the respective punk:
Punk uint | Owner address |
---|---|
0 | 0xe08c32737c021c7d05d116b00a68a02f2d144ac0 |
1 | 0xb88f61e6fbda83fbfffabe364112137480398018 |
2 | 0x897aea3d51dcba918c41ae23f5d9a7411671dee0 |
... | ... |
9999 | 0x2ee43f9a329623f4e97c29d813dff92ee968daee |
To access the owner value for a punk, we use the following syntax:
address punk0Owner = punkIndexToAddress[0]; // 0xe08c32...44ac0address punk1Owner = punkIndexToAddress[1]; // 0xb88f6...98018// Or if we were to use another variable:uint punk = 2;address punk2Owner = punkIndexToAddress[punk]; // 0x897ae...1dee0
More on statements like that later though...