I7 Extras: General Actions, Variables, Switch Case, Taking Inventory
Part 1: The Player, Objects, and Rooms. Part 2: Custom Actions and People. Part 3: Using Conversation Extensions.
I7 Extras: Exposition, Overriding Default Actions, Doors, and Standalone If Conditionals I7 Extras: Basic Screen Effects, Title Screen, Repeat Every Turn, Ending I7 Extras: General Actions, Variables, Switch Case, Taking Inventory (You are here!)
The next installment of I7 extras are things that are not explicitly necessary to making your game better, but it will definitely help you make your life easier (yes, this is true, and life advisers hate this one tip). Let’s get started.
Full post under read more:
General Actions
Whenever we perform an action to an object and have not pre-defined it, the player will receive the default Inform response (example, you see nothing special about X when it is examined).
For this sample game, one of the main defining features of our player character is his relationship with perceiving the world. In the sample room, he interacts with the world by using his keen sense of smell to complete his mission. There are a few objects in the room, and we want him to have a same generic reaction to all of them that isn’t the Inform default.
Where we previously would define a custom definition for each object akin to:
Instead of smelling lamp: say "Smells like cigarettes. Disgusting. [paragraph break] ... And nostalgic.." Instead of smelling file: say " Smells like cigarettes. Disgusting. [paragraph break] ... And nostalgic.."
Now we can comment out the above and use the keyword something to override the default.
Instead of smelling something: say "Smells like cigarettes. Disgusting. [paragraph break] ... And nostalgic..".
Note that if you specify the action on an object that already has a generic case like the one above, Inform will use that specific one. In this case, smelling anything that isn’t a lamp.
Instead of smelling lamp: say "Smells like burnt rubber. [paragraph break] Warm summers on the outback. [paragraph break] Clarissa."
Here we are testing smelling an object (blazer) without defining it specifically and our overridden text.
Variables
It may surprise you, but we’ve been using variables the entire time! Albeit just booleans, other types of variables behave very similarly. Take a look at the I7 For Programmers for a full list of the different types that can be instantiated. For this demo, we’ll be using bools as a refresher and a number variable.
hasExaminedWatch is a truth state that varies. numLookedAtWatch is a number that varies.
The first being whether or not the watch has been looked at, the latter being the number of times the player has looked at the watch. By default, truth states start at false and numbers start at zero. When we look at the pocket watch, we want to set the boolean to true and increment the numLookAtWatch amount.
Instead of examining the pocket watch: say "There are too many cracks on the glass surface to tell time."; now hasExaminedWatch is true; [now numLookedAtWatch is numLookedAtWatch plus two.] increment numLookedAtWatch.
Note the commented out portion. numLookedAtWatch is numLookedAtWatch plus two is the same as saying numLookedAtWatch = numLookedAtWatch + 2.
increment numLookedAtWatch is the same as numLookedAtWatch++
Switch Case
So now you have a counter on how many times the player has looked at the watch. What if we want some reaction to happen depending on the number? We could do something akin to
say “[if numLookedAtWatch is 1] i have done this once [else if numLookedAtWatch is 2] i have done this twise [else if]....”
But that would be time consuming and tedious. Fortunately, there are switch case statements that make this process faster. Here is a sample of combinging the boolean value with the number of times we have looked at the watch.
Instead of smelling watch: say "[if hasExaminedWatch is false] Clarissa [end if]"; if numLookedAtWatch is: -- 0: say " (sigh) "; [if we haven’t looked at it yet, say this] -- 1: say "..."; [if we looked at it once, say this, etc] -- 2: say ".........."; -- 3: say "......................"; -- 4: say "what's the point?"; -- 5: say " .................... [paragraph break] You sigh."; -- 6: say " .... "; -- otherwise: say "no matter how many times you look at it, she won't come back.";
It is important to note that this is extremely space sensitive.
Have a space between '--' and the number (value of your case). Make sure there is no space from the end of you variable to the ':'
Taking Inventory
Giving credit to where credit is due, this is taken from Emily Short’s handy reference tools floating around on the internet. We can define what the player is carrying and wearing at the beginning of the game without explicitly defining each as an object, while treating each object as such.
[What the player is wearing] The player is wearing black trousers, a collared shirt, an old tweed blazer, plain gray socks, and a silver band. The player is carrying a gold pocket watch.
By default, the inventory mentions nothing about what the player is wearing. But we have evolved beyond that stage and have already changed the default behavior interaction with objects- so why not change how the inventory is displayed?
The syntax for the player entering i/inventory is taking inventory and the person playing the game is always referred to in the source as the player.
Instead of taking inventory: say "[if the player carries something][We]['re] carrying [a list of things carried by the player][otherwise][We] bag is empty.";
say "[paragraph break][if the player wears something]. [We]['re] wearing [a list of things worn by the player][else] You probably shouldn't go out in your undergarments. [end if]."
Which will produce this:
Hope that was useful. The full source can be found here!


















