Hi I have this structure, but when I call the function joinLottery, the mapping for gamblers[0] is not updated. Need help to understand why is this happening.

struct Gambler {
    uint token;
    uint encRandomNumber;
    bool exist;
    address gamblerAdd;
    address issuer;

mapping (int =>  Gambler) public gamblers;
uint public currentNumofGamblers=0;

function joinLottery (uint _token, uint _RandomNumber,
    address _issuer){
    Gambler newGambler = gamblers[int(currentNumofGamblers)]; 
    newGambler.token = _token;
    newGambler.encRandomNumber = _encRandomNumber;
    newGambler.exist = true;
    newGambler.gamblerAdd = msg.sender;
    newGambler.issuer = _issuer;
    winningNumber = RandomNumber; 

1 Answer 1


This line is backwards:

Gambler newGambler = gamblers[int(currentNumofGamblers)]; 

You can't assign something to newGambler from gamblers if you haven't put anything in gamblers yet.

Try something like:

gamblers[int(currentNumofGamblers)] = Gambler(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.