state Variable is this : mapping(address=>uint) public userVotes;
now i have a function :
function votePresident(uint _id) external {
presidents[_id-1].voteCount++;
userVotes[msg.sender] = _id;
Voter(msg.sender, _id, userVotes[msg.sender]);
}
the last line is an event. So What happens here is after executing this function, I put an address of the executer in a mapping as a key and value as he passed in. Then I log it.
I have another function where I use this userVotes
function getPresident(uint _index) public view returns (uint, string, uint, string, uint) {
President storage president = presidents[_index];
return (president.voteCount, president.hashImage, president.id, president.name, userVotes[msg.sender] );
}
look at the return line the last parameter, userVotes[msg.sender]
. Unfonrtunatelly, it always returns 0. I don't know why it does that. I checked the log after executing the first function and I didn't see 0. i just saw the actual value. Please help . If I call the getPresident funcction in remix, it returns the actual value and not 0.
msg.sender
just fine in these situations from what I can see.