2

When I fire this function for the first time it seems revealEnd = now; fires because the reveal period ends. Yet revealCount does in fact display '1', indicating that we went into BOTH if statements.

The first time through however the first if statement should be false and revealEnd = now; should be completely skipped...

Is there something wrong here?

function reveal(uint _values, uint _secret)
    onlyAfter(biddingEnd)
    onlyBefore(revealEnd)
{
    //var bid = choices[msg.sender][0]; 

    if (revealCount == 1)
        playerTwoChoice = _values;
        revealCount = 2;
        playerTwoAddress = msg.sender;
        revealEnd = now;

    if (revealCount == 0)
        playerOneChoice = _values;
        revealCount = 1;
        playerOneAddress = msg.sender;
}        
2
  • 6
    you need brackets around the statements after each 'if'. This isn't python... – Paul S Mar 11 '16 at 5:09
  • 2
    @PaulS Please add it as an answer, because 1) this beta needs more answers (meta.ethereum.stackexchange.com/questions/174/…), 2) the question looks like unanswered :) – romanoza Mar 11 '16 at 16:53
6

Solidity has a syntax sort-of borrowed from Javascript. This means it uses braces to denote groups of statements, not whitespace like Python.

You can find complete documentation here.

Your code should look like this:

function reveal(uint _values, uint _secret)
    onlyAfter(biddingEnd)
    onlyBefore(revealEnd)
{
    //var bid = choices[msg.sender][0]; 

    if (revealCount == 1) {
        playerTwoChoice = _values;
        revealCount = 2;
        playerTwoAddress = msg.sender;
        revealEnd = now;
    }
    if (revealCount == 0) {
        playerOneChoice = _values;
        revealCount = 1;
        playerOneAddress = msg.sender;
    }
}        
1
  • Yes was happy to finally see this! Ty – JTicker12 Mar 12 '16 at 6:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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