Actions with different effects in different rooms

Hi all! Apologies if this post is similar to others. I did find some ones that were close to what I want to do, but the tips there are not working for me.

In short, I want different actions to have different effects in different rooms. For example, if my character screams in the library, I want a different response than if they scream in their bedroom.

So my code looks like this:


Instead of screaming:
[if player is in library] say "The librarian rushes towards you and kicks you out.";
[if player is in bedroom] say "You scream. Nothing happens."

When I output this, the code compiles, but it ends up that both lines of text get printed one on top of the other. So what I see is:

“The librarian rushes towards you and kicks you out.
You scream. Nothing happens.”

I also tried this that I found in another post:

Carry out screaming:
say “You scream. Nothing happens.”

Before screaming:
if the player is in the library:
say “The librarian rushes towards you and kicks you out.”

But I get the same result-- code compiles, but both lines of text are printed.

I do have screaming defined in the code, fwiw–

Screaming is an action applying to nothing.

It seems like Inform is not respecting the “if” rule but I am not sure how to change my verbiage so that it works. What am I missing? Thanks in advance.

Instead of screaming:
[if player is in library] say "The librarian rushes towards you and kicks you out.";
[if player is in bedroom] say "You scream. Nothing happens."

Remember more specific rules in I7 take precedence.

After rules fire before Report rules and will stop the action by default. After is good for individualized responses and moving stuff around because of it:

Report screaming:
    say "You scream. Nothing happens."

After screaming when the location is Bedroom:
    say "Nothing happens. Your mom pokes her head in like 'What?'";
    now mother is worried.

After screaming when the location is Library:
    say "The librarian rushes towards you and kicks you out.";
    now the player is in Library Parking Lot.
5 Likes

This worked perfectly! Thank you so much!!

1 Like

Just to elaborate on what’s going on with the square brackets, since it looks like that might be helpful: most of the time square brackets just mark whatever’s in them as a comment, which will be ignored by the compiler (they’re good for notes to yourself or anyone reading the code). It’s only when they come within quotation marks, like as part of a say statement, that they indicate conditionals. So another way to implement this would be:

Report screaming:
	say "[if the location is the library]The librarian rushes towards you and kicks you out[otherwise if the location is the bedroom]You scream. Nothing happens[otherwise]You scream. Nothing happens[end if]."

4 Likes

To demonstrate brackets as comments:

1 Like

I didn’t realize that! That’s really handy to know, because I do often want to leave myself notes for things to elaborate on or fix. Thank you!

2 Likes

And brackets inside quotes can be used for text replacement as well as if-statements as Mike demonstrated.

Report screaming:
    say "[The location] reverberates with your primal utterances."
2 Likes