OR and variables

How does OR work in Inform 7? Like, “If variable is 1 or 2 or 5, …”.

(Also, How do I find stuff like this in the documentation? It works for verbs according to the “Basic actions” chapter, but how do I search for documentation on this question?)

1 Like

In general it works for actions, with some pretty rare caveats depending on circumstance.

It doesn’t work for variables or variable-like situations.

There is an extension (Alternatives by Eric Eve) that allows it to work for variables and variable-like situations in almost all circumstances (https://github.com/i7/extensions/blob/10.1/Eric%20Eve/Alternatives-v3.i7x)

So out of the box, these unrelated lines of code are valid:

if size is 1 or size is 2:

if noun is apple or noun is tree:

if searching or opening the safe:

These aren’t:

if size is 1 or 2:

if noun is apple or tree:

If you include the Alternatives extension, the second pair are valid and that style becomes valid in general.

Sorry I can’t point you to this stuff in the docs because it’s just in my head by now. And Alternatives is not in the docs because it’s an extension.




(One clarification: Alternatives requires the word “either” to make it clear that you’re using its special type of “or” rather than the normal type of “or”. So “if the noun is either the apple or the tree”.)


Yeah, I recalled that when I woke up today.