Help With Conditionals?

Hey guys, I’m fairly new to IF and new to inform (and am generally all around awful with computers). Mostly, I’m a writer who thought it would be fun to translate a story line into IF format. I’ve got the basics, but one thing is still tripping me up; conditionals.

I understand the whole “instead” conditional. I’ve got that. But what I don’t understand is how to make one action depend on another. For instance, I have the character “Mom” who I have defined as being “a woman in the Kitchen”. For the purposes of this game. I want the player to have to talk to “Mom” before leaving through the door. Unfortunately, I can’t figure out how to code this properly. If I say “instead of opening the door, say” whatever, then the door will never open. I don’t know how to make the opening of the door dependent on whether or not the character has talked to “Mom”.

Also I find a similar issue with a vehicle. I want the character NOT to be able to enter or re-enter any other rooms (except a few designated areas, like streets and driveways) once inside the car. But I don’t know how to prevent her from entering somewhere based on the fact that she is in the car.

I’ve combed through the documentation and even an extra manual I found online, and while the extra manual mentions similar issues (such as a guard dog not letting you enter until you complete a certain task; namely, distracting it) they don’t actually blatantly tell you how to do it yourself.

Any help would be appreciated! Also any other tips would be warmly welcomed!

I’m not sure if this is the most elegant way to accomplish this since I’m just a newbie myself, but you could use “Check”.

[code]Talking is an action applying to one visible thing. Understand “talk to [someone]” as talking

Instead of talking:
if the noun is mom:
say “‘Hi mom!’ you say.”;
now mom is talked-to

Check opening the door:
if mom is not-talked-to:
say “You should really talk to mom first.” instead.[/code]

Though that only covers really basic talking. For more complex talking, I suppose you can do something like this:

[code]Mom is a woman. Mom is in your room.

Mom has a number called Talked-to number. The talked-to number of Mom is 0.

After asking Mom about “grilled cheese”:
say “‘Oh honey, you know the Martians ate all of that over Christmas. Maybe next time, okay?’”;
increase talked-to number of Mom by 1

After asking Mom about “Dad”:
say “‘You just missed him, sweetie, but he sends his good luck on your whatitmacally, whatever you do when you aren’t at home.’”;
increase talked-to number of Mom by 1

After asking Mom about “intergalactic space tennis”:
say “‘That’s nice, darling.’”;
increase talked-to number of Mom by 1

Check opening the door:
if the talked-to number of mom is less than 3:
say “You should probably talk to mom some more.” instead.[/code]

As for the driving car thing, I’m not sure since I haven’t tested it fully, but it should work.

[code]Include Rideable Vehicles by Graham Nelson.

The car is in the Street. The car is a rideable vehicle. The house is south of the street. The highway is west of the street.

The Do-Not-Drive Zone is a region. The house and the garden is in the Do-Not-Drive Zone.

Check going to the Do-Not-Drive Zone:
if the player is on the car:
say “You aren’t smashing into your house. Get out the car and walk.” instead[/code]

Thanks for the advice! It’s…sort of working? It doesn’t seem to understand the condition of being “talked-to” . I’m not sure how to make that a condition that it will understand. It says in the error message that it was expecting a condition but received something unrecognizable (the “talked-to”). Any guesses on how to fix that?

The reason you get the error message is that you have to explicitly give Mom the either/or property ‘talked-to’ (just like you explicitly give her the number ‘talked-to number’ in Bistre’s second example) in order to refer to the property (or the number).
You do that easily enough:

Mom can be talked-to. Mom is not talked-to. 

(The last phrase is probably not necessary, but it makes sure that Mom is not talked-to by default.)

(If you’re not interested in any extended conversation between Mom and the player character, but only wish him automatically to tell Mom something before he leaves the kitchen, you could do it like this:

Instead of opening the kitchen door when Mom is not talked-to: say "At the door you suddenly hesitate. 'Bye mom!', you say and turn to face her. 'I'll be back a rich and famous man.' Your mother looks at you, tears in her eyes, uttering an ancient Philadelphian blessing: 'Take care, my son.'"; now mom is talked-to.
[/code])

Also, you don't actually need to include the Rideable Vehicles extension to use vehicles. That extension is only meant for vehicles you ride ON (like you ride on a horse or a bike). Vehicles you ride IN (as you ride in a car) come built-in. 
(That's because by default vehicles are containers that you go inside  – and things can't be both containers and supporters, so you need the trickery that the extension works to have vehicle-like objects that you go onto.)

An extra tip: there's an action variable for the going action, viz. 'the room gone to', that comes in handy for text substitutions in cases like this:
[code]Check going to the Do-Not-Drive Zone: if the player is in the car, say "No, you mustn't drive your car into [the room gone to]. Mom wouldn't approve. And as Granny would have said: 'If you can't get'em where you put'em, you can't hav'em when you want'em', meaning (you think) she wouldn't have approved either." instead.

(Note that the player character is “IN the car”, if you’re not using the Rideable Vehicles extension.)

Thanks for the help! For note, if anyone else is reading this thread trying to figure the same things out, you must put “A person can be talked-to or not-talked-to” . When I put “Mom can be talked-to or not-talked-to” it flipped out and gave me another error message, but it works fine with the former.

“Mom can be talked-to or not-talked-to” is legal in general. I mean, if Mom is an object. If it didn’t work for you, it must have conflicted with some other code you wrote.

Ok, one more question, which is actually a coding question for a friend of mine. She’s trying to figure out how to code conditionals with attacking. It’s much more complex than mine. I tried to help her out with what I know from here, but it’s not working. Let me show you the code:

[code]A person can be attacked or not-attacked.

Understand “kill leader/use saber on leader/throw saber at leader” as “[attack leader]”

Instead of attacking:
if the noun is Leader
say “Your blade meets the man’s with a ring and a sickening squeal as the iron grinds together. He’s huge, nearly a foot taller than
you, and after a valiant effort on your part he forces the blade from your grip. It thuds to the ground where he kicks it out of your
reach before you can make a grab for it. You always try to tell Bernhard that a dagger was more your style but he never listens.”;
Leader is now attacked

Check attacking Leader:
If Leader is not-attacked:
After waiting for the first time:
say “The man in the black tunic is squaring off with you. It occurs to you that now would be the time to use your saber. After
all, the CB didn’t ask you to save lives.”
After waiting for the second time:
say “The man raises his battleaxe and charges you. You notice…”
After waiting for the third time:
say “The thieves’ leader…”; end the game in death.

If Leader is attacked:
     After waiting for the first time:
           say "The thieves' leader..."; end the game in death.[/code]

What’s tripping inform up (for the moment, anyway) is “If Leader is attacked” and the subsequent colon. I really don’t understand why this is, especially when it seems to be fine with “If Leader is not-attacked” unless it’s just not currently showing an error message there…

Thoughts?

Well, there’s a couple issues going on. The big one is that the sentence before “if leader is attacked” ends with a period, not a semi-colon, which signals to Inform that that code chunk has ended. Therefore, it doesn’t know what to do with the line beginning with “if leader is attacked”.

Your friend is also going to run into problems because the instead rule written is going to prevent any of the check/carry out rules for attack from firing. It also seems to be missing a colon on after “if the noun is leader” and a semi-colon or period after “leader is now attacked”. If fact, there’s all kinds of missing punctuation. Basically, every line end needs either a semi-colon or a period. The last line in a code block gets a period; the rest should get semi-colons.

Rules from different rulebooks can’t be combined; “After waiting” should not be under “Check attacking”, because those things will never happen simultaneously (and Inform doesn’t know how to handle it.)

Here’s a working example. I’ve put all the attack code relevant for the leader in one “instead of attacking the leader” block. This completely bypasses the rest of the attack rules, so if you decide in the future that the player can’t attack unless she’s carrying the Vorpel Blade of Gore, you’ll have to do some revisions.

It looked to me like you wanted the death sequence to happen as the player waited, but as noted in the comments, it could just as easily go every turn. (Right now, the player character can open things, try on tiaras, talk to their friends, etc. without the fight progressing.)

There’s some pretty specific grammar for declaring things in Inform; “now leader is attacked” is necessary rather than “the leader is now attacked”.

I put in a “encounter count”, which is similar to the waiting tag that was being used earlier. However, that would have fired if the player had waited anywhere any earlier in the game, even if the leader wasn’t present. This is more specific, and resets itself if the player leaves the room and returns. (I’m pretty sure this should work, but I am using 6E72 rather than the most recent version.)

Is your friend compiling/testing every line or two? I still find that massively worthwhile; it seems time consuming, until you have to find the one hidden bug in twenty lines of code, which is much harder than it has any right to be.

[code]“ATTACK!”

A person can be attacked or not-attacked.

Understand “kill leader/use saber on leader/throw saber at leader” as “[attack leader]”

Instead of attacking the Leader:
if the Leader is not-attacked:
if the player is carrying the broadsword:
say “Your blade meets the man’s with a ring and a sickening squeal as the iron grinds together. He’s huge, nearly a foot taller than
you, and after a valiant effort on your part he forces the blade from your grip. It thuds to the ground where he kicks it out of your
reach before you can make a grab for it. You always try to tell Bernhard that a dagger was more your style but he never listens.”;
move the broadsword to the location;
otherwise:
say “You swing gamely at the man with your fist, and dodge back with a curse as he raises his blade, grinning.”;
now Leader is attacked;
otherwise:
say “This fight is clearly over, and you are not the victor.”;

Check waiting: [This could be replaced by “Every turn” if you like; right now it fires only if the player is actively waiting.]
if the encounter count is 1:
say “The man in the black tunic is squaring off with you. It occurs to you that now would be the time to use your saber. After all, the CB didn’t ask you to save lives.” instead;
otherwise if the encounter count is 2:
say “The man raises his battleaxe and charges you. You notice…” instead;
otherwise if the encounter count is 3:
say “The thieves[’] leader brings his axe in for a swift blow; you have just enough time to admire his technique before it slices through your chest.”;
end the game in death;

Every turn: [Likewise, this could be a “check waiting” or “after waiting” rule - it all depends how you want it]
if the Leader is in the location:
increase encounter count by 1;
otherwise:
now encounter count is 0;

The Sparring Room is a room. The player is carrying a broadsword.
The leader of the thieves is a man in the Sparring Room.

Encounter count is a number that varies. Encounter count is 0.[/code]

Some last lousy points.

The line

will not work as intended.

For one thing, “the slash indicates a choice between words only, not between entire phrases” (to quote Writing with Inform). It’s only the very words on either side of the slash that are exchangeable. What that means is that the line above makes “[attack leader]” a token for “kill leader saber on leader saber at leader”, “kill leader saber on throw saber at leader”, “kill use saber on leader saber at leader”, and “kill use saber on throw saber at leader” – but NOT for “kill leader”, “use saber on leader” or “throw saber at leader”.

I suppose a syntactically correct way to do it would be ‘Understand “kill leader”, “use saber on leader” and “throw saber at leader” as “[attack leader]”.’. However, Inform will not understand “[attack leader]” as intended anyway – i.e as a token for commands triggering the action of attacking the leader.
You define commands for actions a little differently.

It seems that your friend wants “kill”, “use saber on” and “throw saber at” as synonyms for “attack”, but only when the player attacks the leader. She could do that this way:

Understand "use saber on [leader]" and "throw saber at [leader]" as attacking.

(Inform already by default understands the command “kill” as “attack”, so she need not bother about that.)

Or, if she wants “use saber on” and “throw saber at” as synonyms for “attack” generally, regardless of whom or what is attacked:

Understand "use saber on [something]" and "throw saber at [something]" as attacking.

(For the sake of clarity:

… except when you write ‘Test me with’-commands. In that particular context you can write things like Test me with "attack leader / kill leader / use saber on leader / throw saber at leader / flee." and Inform will understand it as intended. But in all other contexts it’s only the very words on either side of the slash that are exchangeable.)

Wow, thanks so much, guys! We’re both really new at this. I’m sure she’ll appreciate the help. I think she needs to learn how to do turns and things, which I have no idea how to work and have very little desire to figure out at present.

I don’t really get the different punctuation rules (differences between colon and semi-colon, for instance) or the rules for indentation, so it’s back to the manual on that for me!

Having some conditional issues for some reason. I’ve been mired in this particular bit of code for about five hours now. I’ve rearranged, rephrased, and done just about everything else but nothing seems to help.

Inform accepts my code as correct but the problem I’m facing is that it seems to have ignored my “if the ferret is not in the room” rule entirely.

[code]Service Door is a door. The description of Service Door is “The service door is a reinforced aluminum door. It looks worn as if its seen a lot of use.” Service door is east of The Shadow of the Plateau and west of Main Bay. Service Door is scenery. Service Door is lockable and locked. Service door is openable.

Instead of opening the Service Door:
if the Service Door is locked:
say “You jiggle the handle but you can feel the deadbolt holding it shut. There isn’t even a place for a key on this side.” ;
if the Service Door is unlocked:
say “You have to put your shoulder into it but the old door opens.”

Bay Door is a door. The description of Bay Door is “The bay door is twice your height and about 50 meters wide. Big enough to fit a tank, or several, perhaps. It looks automatic.” Bay Door is southeast of The Shadow of the Plateau and southwest of Main Bay. Bay Door is scenery. Bay Door is closed and openable.

Instead of opening the Bay Door:
if the ferret is in the room:
if the Bay Door is closed:
say “The ferret, sensing your struggle, skitters up the wall of the garage and into a fist-sized hole between the bay door and the wall. A moment later the automatic door shudders and begins to heave open slowly. You may never know how the ferret figured that out. He really deserves a name for that stunt.” ;
now the Bay Door is open;
now the Bay Door is not openable;
otherwise:
if the Bay Door is closed:
say “There doesn’t seem to be a way to open it from this side.”[/code]

No ferret in sight and yet he shows up to open the door for me.

It seems like it’s checking if the ferret is on-stage, that is in a room. If you said somewhere in your code that

A ferret is an animal in Very Special Hidden Room.

then ferret being in a room is true.

Try

if the ferret is in Main Bay

if you’d like the door to be open only if the ferret is in one specific room (you could even put the ferret in Control Room and he’d jump on the button opening the door for you), or

if the ferret is in the location of the player

if the ferret is your friend and opens the door only when he’s with you.

Thank you so much! The simple change to “main bay” vs “the room” made all the difference! Of all the things I tried, that never occurred to me. :unamused:

Yeah, this comes up about twice a week. I7 doesn’t interpret “the room” or “the person” or etc the way you expect; such references always wind up meaning “a room” or “a person”.

Since this issue is so ubiquitous, I’ve posted a uservoice suggestion that the documentation mention it more often and more prominently.