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
    Commented Mar 11, 2016 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
    Commented Mar 11, 2016 at 16:53

1 Answer 1

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;
    }
}        
2
  • Yes was happy to finally see this! Ty
    – JTicker12
    Commented Mar 12, 2016 at 6:00
  • Note that you may omit braces for single instruction if
    – Oli Crt
    Commented Apr 1, 2023 at 18:37

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.