1

I've created my own struct:

 enum TestState {noWager, wagerMade, wagerAccepted}

And my modifier:

modifier onlyState(GameState expectedState){
    if(expectedState == currentState){ _;}
    else{throw;}}

I'm wanting to allow a function to be carried out if it is either noWager or wagerMade state.

 function testWager() onlyState(GameState.noWager || GameState.wagerMade) payable returns(bool){....}

I am getting the error:

 || not compatible with types enum GameState and enum GameState
4

Here's one way to do it:

pragma solidity ^0.4.2;

contract Test {
    enum GameState {noWager, wagerMade, wagerAccepted}

    GameState public currentState;

    modifier onlyState(GameState expectedState) {
        if (expectedState != currentState) {
            throw;
        }
        _;
    }

    modifier onlyStates(GameState expectedState1, GameState expectedState2) {
        if (expectedState1 != currentState && expectedState2 != currentState) {
            throw;
        }
        _;
    }

    function testWager() onlyStates(GameState.noWager, GameState.wagerMade) payable returns (bool) {

    }
}

And the Browser Solidity screenshot showing the successful compilation:

enter image description here

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.