# Slightly complex ifs?

Good afternoon! Forgive me if this question is either obvious or has already been asked, but I’m a little stumped.

In the IF I’m working on on Inform 7, I’ve reached a particular scenario where the player is a bit of a matchmaker between chaarcters called Jeremy and Felicity. Felicity is not very openly fond of Jeremy, who asks the player to deliver a bouquet of wilting, unimpressive flowers to her. However through a series of other events, the player discovers that Felicity has a weakness for red roses. After finding red roses, the idea is to replace the boring flowers in the bouquet with the red roses, at which point Felicity drops an object needed to continue. This is fine, but it’s when it comes to the actually giving of the bouquet that I have trouble. This is what I have:

```Instead of giving the bouquet to Felicity: if the bunch of roses is in the bouquet, say "Felicity looks at the beautiful roses for a moment in shock, but nevertheless takes them and holds them to her chest uncertainly, looking at you curiously.[paragraph break]Excited, Aisha leaps up at her mistress, trying to sniff the flowers, but in the process knocks a silver object out of Felicity's handbag. The woman, preoccupied by her canine friend, seems not to notice."; move the bouquet to Felicity; now the handbag is open; move the silver object to the tearoom; if the yellow flowers are in the bouquet, say "You hold out the flowers to Felicity. She looks at them distastefully, glances at the label, and turns away."; if there is nothing in the bouquet, say "Felicity looks at the empty mess of crêpe in confusion, sighs angrily, and turns back to the window."```

The problem is that even if the bouquet’s contents are unsatisfactory, it moves to Felicity and (although the text describing the silver object being dropped isn’t shown) the handbag opens and the silver object moves to the tearoom all the same.

I could avoid this by, on the other ‘if’ branches, commanding the silver object to return to the handbag and the handbag to close, but that seems unnecessarily long-winded. Is there a more efficient way of doing this?

Hi (and welcome to the forum!),

in your code, the statements “move the bouquet to Felicity;” etc. are not grouped into a block following the if condition. You need to group the different blocks of statements with colons after the if conditions, like this:

``````Instead of giving the bouquet to Felicity:
if the bunch of roses is in the bouquet:
say "Felicity looks at the beautiful roses for a moment in shock, but nevertheless takes them and holds them to her chest uncertainly, looking at you curiously.[paragraph break]Excited, Aisha leaps up at her mistress, trying to sniff the flowers, but in the process knocks a silver object out of Felicity's handbag. The woman, preoccupied by her canine friend, seems not to notice.";
move the bouquet to Felicity;
now the handbag is open;
move the silver object to the tearoom;
otherwise if the yellow flowers are in the bouquet:
say "You hold out the flowers to Felicity. She looks at them distastefully, glances at the label, and turns away.";
otherwise if there is nothing in the bouquet:
say "Felicity looks at the empty mess of crêpe in confusion, sighs angrily, and turns back to the window."``````

Cf. the documentation, Chapters 11.5. “Conditions and questions” to 11.8. “Otherwise”.

Speaking of chapter 11: if you’re having trouble with the indentation style of if statements, you might want to consider the begin/end if style.

Ahh, wonderful, thank you! Worked like a charm. I hope it’s okay if I ask another question in this same thread?

I want to change the default message received when the player tries to eat something inedible.

``````Before eating something:
if the noun is not edible:
say "Well, you can try...[line break][line break]...Sorry, you failed.";
Do not say default message;
otherwise:
continue the action``````

This does return my personalised message, but it also gives the default one. That is to say, it returns:

Which is something I don’t want to happen. Is there a way of fixing this?

Try this.

``Before eating something inedible: say "Well, you can try...[paragraph break]...Sorry, you failed." instead.``

Hope this helps.

I’m a big fan of keeping rules as small as possible. Among other benefits you can often drop if-conditionals completely and avoid hard to spot bugs in complex conditionals. That instead-rule could be split into three smaller ones:

[code]Instead of giving the bouquet to Felicity when the bunch of roses is in the bouquet:
say “Felicity looks at the beautiful roses for a moment in shock, but nevertheless takes them and holds them to her chest uncertainly, looking at you curiously.[paragraph break]Excited, Aisha leaps up at her mistress, trying to sniff the flowers, but in the process knocks a silver object out of Felicity’s handbag. The woman, preoccupied by her canine friend, seems not to notice.”;
move the bouquet to Felicity;
now the handbag is open;
move the silver object to the tearoom.

Instead of giving the bouquet to Felicity when the yellow flowers are in the bouquet:
say “You hold out the flowers to Felicity. She looks at them distastefully, glances at the label, and turns away.”

Instead of giving the bouquet to Felicity when there is nothing in the bouquet:
say “Felicity looks at the empty mess of crêpe in confusion, sighs angrily, and turns back to the window.”[/code]

I’d probably suggest something like this.

[spoiler][code]“Test”

The block giving rule is not listed in the check giving it to rulebook.

Check inserting something into the bouquet (this is the can only put flowers in the bouquet rule): if the noun is not the yellow flowers and the noun is not the bunch of roses, say “You can’t put that into the bouquet!” instead.

Check giving the bouquet to Felicity when there is nothing in the bouquet (this is the check giving an empty bouquet rule): say “Felicity looks at the empty mess of crêpe in confusion, sighs angrily, and turns back to the window.” instead.

Check giving the bouquet to Felicity when the yellow flowers are in the bouquet (this is the check giving a bouquet with yellow flowers rule): say “You hold out the flowers to Felicity. She looks at them distastefully, glances at the label, and turns away.” instead.

After giving the bouquet to Felicity when the bunch of roses is in the bouquet (this is the after giving a bouquet with roses rule):
say “Felicity looks at the beautiful roses for a moment in shock, but nevertheless takes them and holds them to her chest uncertainly, looking at you curiously.[paragraph break]Excited, Aisha leaps up at her mistress, trying to sniff the flowers, but in the process knocks a silver object out of Felicity’s handbag. The woman, preoccupied by her canine friend, seems not to notice.”;
now the handbag is open;
move the silver object to the tearoom.

The TeaRoom is A Room. Felicity is a person in the tearoom. Felicity holds a handbag.

The handbag is a closed container. The silver object is in the handbag.

The bouquet, some yellow flowers and a bunch of roses are in the tearoom. The bouquet is a container. The carrying capacity of the bouquet is one.

Test me with “give bouquet to felicity / put flowers in bouquet / give bouquet to felicity / take flowers / put roses in bouquet / give bouquet to felicity / l / take silver”.[/code][/spoiler]

It’s generally better to use an after rule here rather than an instead, since the giving action is actually happening.

Hope this helps.

Thank you all very much, I think I understand far better now. You’ve been a great help!

Just two more quick questions: how would I replace the default message when taking an item (That is to say, the simple “Taken.” message)? I tried the same structure as the inedible items bit above, but then of course the item isn’t actually taken, it remains where it was before.

Second question - is there a way to make an object in an open container hidden unless the container itself is examined, so that when the container is listed in the “You can see…” description of the room, it says just “…a thing, a container, another thing…” rather than “…a thing, a container (in which is something else), another thing…”, but the contained item is still listed in the description of the container?

For the container, the manual suggests this (slightly hidden away in Ch. 17:10):

``Rule for printing the name of the bowl: say the printed name of the bowl; omit contents in listing.``

for a single thing called “bowl”.
Or

``Rule for printing the name of a container (called the item): say the printed name of the item; omit contents in listing.``

for any container in the game.

As for replacing “Taken”, you can try an after rule:

``After taking: say "You pick up [the noun]."``

Actually, you can also write it like this.

``Before printing the name of the bowl: omit contents in listing.``
``Before printing the name of a container: omit contents in listing.``

Also, if you want to change the taking message for just the bowl, you can use this.

``After taking the bowl: say "You pick up [the noun].".``

Hope this helps.

Ah, yes! The code I proposed just didn’t feel familiar, yet I couldn’t recall the usual, proper of way of doing it (i.e. with a before printing the name of something rule). Thanks!