I am fairly new to Solidity and I wanted to understand the Push function better. I am using solidity ver 0.5.12 I wanted to push the Owner address into an array as follows
address Owner;
constructor() public
{
Owner = msg.sender;
}
address[] playersAddressList;
playersAddressList.push(Owner);
Remix is giving me an error stating browser/Lottery.sol:53:32: ParserError: Expected identifier but got '(' playersAddressList.push(Owner); ^
However, when I am trying to push the Owner into an array inside the following function there is no error
function addPlayer(string memory a, uint b) public payable
{
playersAddressList.push(Owner);
address creator = msg.sender;
playersAddressList.push(creator);
balance = balance + msg.value;
require (msg.value >= 1 ether);
person memory newPerson;
newPerson.name = a;
newPerson.age = b;
players[creator] = newPerson;
}
I wanted to understand why I can push the Owner's address to an array inside the function but not outside it?
Thanks Rwiju