contract MyIfElse {
uint256 public revealState = 0;
bool public isNowRevealed = false;
function addToRevealState () private {
revealState++;
}
function isRevealed () public {
if (revealState >= 10){
isNowRevealed = true;
addToRevealState();
}else{
addToRevealState();
}
}
}
When the revealState()
is called, addToRevealstate()
gets triggered as intended because the if else
statement hasn't been met.
The problems occurs when the revealState
= 10. The isNowReveal
bool does not update the state to true
. Only after revealState
= 11 will the state be updated to true
.
Is there an indexing issue I'm not taking into account?
revealState
is10
, callingisRevealed
does not setisNowRevealed
totrue
?realState
is now 11 beforeisNowRevealed
turnstrue
.revealState
will turn 11 whenisNowRevealed
turnstrue
, but it is10
when the transaction that flipsisNowRevealed
totrue
begins! So you have a state like this, where each new state is the result of a call toisRevealed
(0, false) -> ... -> (9, false) -> (10, false) -> (11, true). Thetrue
only shows up whenrevealState
is11
because you always incrementrevealState
after settingisNowRevealed
totrue
. But the flip happens whenrevealState
is10
.