Alternatives

version 2 by Eric Eve

  • Home page
  • Beginning
  • Next



  • Documentation


    Chapter: Alternatives

    Section: The Basics

    This extension adds a number of conditions that can be used with IF, WHEN and the like:

        X is either A or B
        X is either A or B or C
        X is either A or B or C or D
        X is either A or B or C or D or E
        X is either A or B or C or D or E or F

        X is neither A nor B
        X is neither A nor B nor C
        X is neither A nor B nor C nor D
        X is neither A nor B nor C nor D nor E
        X is neither A nor B nor C nor D nor E nor F
        
    For this to work, either A, B, C, D, E and F must all be the same kind of value as X. Thus, for example, if X is an object, A, B, C etc. must all be objects or if X is a number then A, B, C etc. must all be numbers. Apart from this restriction, these phrases can be used with any kind of value, including new kinds defined by a game author. This allows us to use tests like:

        if the colour of the noun is either red or blue...

        Instead of eating the noun when the colour of the noun is neither blue nor orange nor green...

    (Assuming, of course, that we have defined colour as a kind of value which includes red, blue, green and orange among its possible values). Note in this case that we must test "the colour of the noun" not just the "noun"; the following condition will not compile:

        If the noun is either red or blue,

    Instead we must write:

        if the colour of the noun is either red or blue...

    The reason is that the phrase is testing for literal equality, and a thing can never be equal to a colour.