As another little Inform 7 educational infomercial, let’s check out the code that @lpsmith wrote to summon mist – a key ability of the protagonist of his game. I’m adding some line breaks for forum readability.
The grey mist is a backdrop.
A backdrop is a special kind of object in Inform that can be in many rooms at once. It is ideal for implementing things that are (a) visible from many locations, such as the sky or a distant mountain; or (b) reappearing in many rooms, but can always be handled by the same code, such as a ceiling, if you have a reason to implement ceilings. In this case, if the grey mist gets summoned, it should be visible in every location, so using a backdrop makes a lot of sense.
The grey mist can be summoned or unsummoned.
The grey mist is unsummoned.
The first line sets up two possible states for the grey mist; the second sets the initial state.
The description is "[if summoned]Grey mist swirls and surrounds you, covering you like a blanket.[otherwise]The cloud layer today is too high for a naturally obscuring mist; you'll have to summon it yourself."
I experience a lot of pain when reading this – there is no ‘[end if]’! That’s almost as bad as having an opening bracket but no closing bracket. (But apparently it is legal in Inform.
Understand "cloud/clouds/gray" as the grey mist. The grey mist is everywhere.
Understand lines set up synonyms. ‘Everywhere’ can, I think, only be used with backdrops. It tells us that the backdrop appears in every room.
Summoning is an action applying to one thing. Understand "summon [something]" as summoning.
Here we set up a new action. The chef could have chosen to write a summon mist action that gets called by typing “summon mist”, but instead has written a general summoning action that can be applied to any present object. It can only be applied to the mist because the mist is present even when it is not summoned; as a backdrop that is everywhere, it is also there when it is in the unsummoned state, although I presume it will then never be described. Does this choice for a general action mean that there will be other things to summon during the game? We do not yet know.
The chef will now have to give us code for summoning other objects – probably just rejecting the attempt – and that is exactly what happens:
Check summoning something:
if the noun is not the grey mist:
say "You're a Bostrat: you can summon mist and clouds, but nothing else." instead.
Note that a check rule runs before a carry out rule. The ‘instead’ ensures that the rule reports failure, and so the summoning never goes to the carry out stage if the noun – the object mentioned in the command – is not the mist. Note, by the way, that the current implementation of this check rule ensures that nothing but the grey mist could ever be summoned.
Carry out summoning the grey mist:
if the grey mist is summoned:
say "You draw even more moisture from the air, feeding it into the mist. It's still just as obscuring as before, but you feel safer, as you always do in the midst of clouds.";
otherwise:
say "[one of]Calling on your heritage as a Bostrat, you summon moisture from the air, and it slowly coalesces into a creeping grey mist, obscuring you from sight. In gentler times, you would be doing this to ensure the growth of the fields and forests; now you must use it to hide from prying eyes that would keep you from your quarry[or]You summon an obscuring grey mist to surround you and hide you from prying eyes[stopping]."
This rule merely describes the summoning, but does not change the game state. Note that the ‘one of’, ‘or’, ‘stopping’ structure ensures that you see the text before the ‘or’ only the first time you summon the mist, and the text after the ‘or’ every subsequent time. This is a good structure to use when you want to describe an effect in detail initially, but don’t want to repeat all that detail later.
Changing the game state is done by the next rule – I’m not sure why this doesn’t happen in the carry out rule, but perhaps @lpsmith and I have a different idea of what ‘after’ rules are for! It is anyway unimportant, nothing hinges on the choice here. After rules run after carry out rules.
After summoning the grey mist:
now the grey mist is summoned;
continue the action.
All the action does is change the mist from unsummoned to summoned. The actual impact this has on the game will be coded elsewhere; for now the game can always check whether the mist is summoned, and react accordingly.
Wait, I forgot something.
)