I’m going back over the Ethereum smart contract 101 to really get it in my head.
This compiles.
I’m wanting to be able to enter the array/struct position +1
to call items, so the index will start at 1.
This bit works for the first item:
(people.length += 1)
… When I call index 1 I get the first entry. Index 2 results null.
I’m thinking I need to set a counter somewhere.
This is the contract:
pragma solidity 0.5.12;
import "./Ownable.sol";
contract HelloWorld is Ownable {
struct Person {
uint id;
string name;
uint age;
uint height;
}
Person[] public people;
function createPerson(string memory name, uint age, uint height) public payable {
people.push(Person((people.length), name, age, height));
/*(people.length +1) adds 1 to ID, so ID starts at 1.
(people.length += 1) ... When I call index 1 I get the first entry. Index 2 results null tho.*/
}
}