Nested if statements are giving me issues

I want the player to have to tell the robot to go away before they can get in the room, like the robot is guarding the room. I tried making this work, and after many attempts I got something to compile, but as I tested there was problem after problem, and I kept changing things to try to get it to work. Finally, I’ve gotten to the point where when the robot leaves, you can go in the room, but when you try to go north to get out, literally nothing happens. Could someone help? I would also appreciate it if someone could tell me where to find a good, thorough explanation of nested if statements in general, or, if it’s easy, just give me tips yourself. Here’s my code so far.

M Living Room is a room. "East goes to the hallway." M Living Room is east of Street N. 
M Hallway is a room. "West goes to living room, east goes to girls room. If you can't get in the Girls Room, type 'robot, go west.'" M Hallway is east of M Living Room.
Girls Room is a room. "North goes to hallway." Girls Room Door is a door.  Girls Room Door is lockable and locked. Girls Room Door is south of M Hallway. Girls Room Door is north of Girls Room.

Robot is a person. Robot is in M Hallway.
Persuasion rule for asking Robot to try going somewhere:
	persuasion succeeds.

Instead of going through Girls Room Door:
	if Girls Room Door is closed and Girls Room Door is locked:
		if Robot is in M Hallway:
			say "The robot won't let you through.";
			now player is in Girls Room;
			now Girls Room Door is unlocked.

If this helps, when I remove the line saying that the door is lockable and locked, the game does nothing when you’re in the hallway going south (towards the Girls Room.)

1 Like

This is a pretty general rule: it will kick in whenever you go through the door, even when the door is open or unlocked.

This if doesn’t have an otherwise attached. That means that if the door is open or unlocked, nothing at all will happen. Sounds like what you’re seeing!

The right fix depends on what you’re trying to do, but usually what you want is to make the rule as specific as possible; something like:

Instead of going south through Girls Room Door when Robot is in M Hallway:
	say "The robot won't let you through."

That way your rule only applies in the specific cases that you want.