How to make relations and states in Inform 7

0 votes
115 views
asked Apr 18 in Authoring by almightyjanitor (3 points)
edited Apr 18 by almightyjanitor

Actually, I'm not sure if relation is the right thing for this, but as far as I understand the documentation, I'm at least looking at the right section.

Scenario: I have a radio that says things, but I keep having to copy and paste this:

[if the player can see the radio and radio is switched on and battery compartment contains a battery]

  • I know that using visibility to determine if the player is within range of the radio is a crappy temporary solution. Checking if the radio is in the same room as the player would be an improvement, and an audibility model would be even better. I haven't been able to find anything in the index that works like "in the presence of".

  • Instead of typing the big if statement, is there a way I can give the radio a "heard" state that checks for audibility, being turned on, and having batteries, so I can condense the condition down to [if radio is heard]? (And doesn't involve adding "now the radio is heard" all over the code.)

2 Answers

+1 vote
answered Apr 18 by bg (692 points)
selected Apr 19 by almightyjanitor
 
Best answer

To check if the radio is in the same room as the player, you can say "if the radio is enclosed by the location." ("The location" is short for "the location of the player".) This condition (as opposed to "if the radio is in the location") would be true even if the radio is carried by the player, or is inside a container in the same room. There's more on enclosure in §3.25 of Writing with Inform.

I'm not sure what you'd want the conditions to be for deciding whether something is audible. You could skip the enclosure condition and substitute a touchability condition (see §6.13) if you don't want the radio to be audible from inside a closed container.

To create a "heard" condition, you could use "to decide if" (see §11.16 of Writing with Inform).

Place is a room.

A radio is a device in Place. A container called battery-compartment is part of the radio. The printed name of battery-compartment is "battery compartment". Understand "battery/-- compartment" as the battery-compartment.

Some batteries are in the battery-compartment.

Instead of listening to the radio:
    if the radio is heard:
        Say "Static comes from the radio.";
    Otherwise:
        Say "You can't hear anything coming from the radio."

To decide if the radio is heard:
    if the radio is enclosed by the location:
        if the radio is switched on:
            if the battery-compartment encloses the batteries:
                yes;
    no.

Test me with "listen to radio / switch on radio / listen to radio".

The way my example is set up, though, there's actually not much use for specifying that the radio has to be enclosed by the location, because the listening action already requires a touchable noun (you can see this if you click the Index tab and then the Actions tab, and scroll down to the alphabetical list of actions). If the radio is not enclosed by the location, it's not going to be touchable.

+1 vote
answered Apr 19 by anonymous

Any time you find yourself repeating an if condition, wrap it with a "decide" phrase. So in this case

To decide if the radio can be heard:
   if the radio is visible and the radio is switched on and the battery compartment contains a battery, decide yes;
   decide no.

This is particularly useful because, if any other conditions arise later in the game (has the player gone deaf? Has the radio broadcaster gone off air? etc.) you've got a single place to add that logic in.

This site is now closed.
As of 1st November 2015, this site is a read-only archive. For more information see the intfiction forum post

Welcome to IF Answers, a site for questions and answers about Interactive Fiction.

Technical questions about interactive fiction development tools such as Inform, Twine, Quest, QuestKit, Squiffy, Adrift, TADS etc. are all on-topic here.

Non-technical questions about interactive fiction are also on-topic. These questions could be about general IF design, specific games, entering the IF Comp etc.
...