Before versus instead

I’m trying to add a little more depth to my game. So instead of having the player read: “You can’t go that way” when they try to go some direction that’s not allowed, I wanted to add some varied responses. Below is an example of what I’ve tried but the game still only tells the player “You can’t go that way.”

Instead of going north from Central City North/East Lanes:
	say "You begin to walk North but the quick odor of something edible coming from the South stops your feet."

Should I have used “before” rather than “instead”?

This is a subtle point – you have to say “Instead of going north in ROOM”. It’s not “from ROOM” if the player fails to leave!

2 Likes

Got it! That did the trick, thank you.

If you want a little more flexibility and perhaps better performance, you could do something like this:

room1 is a room.
room2 is north of room1.

check going in room1:
	if going south:
		say "no way" instead;
	otherwise if going east:
		say "you cant go east." instead;
	otherwise if not going north:
		say "bah! there's nothing for you there. The only way forward is to the north" instead;
	otherwise if going north:
		say "you cautiously make your way north.";
		continue the action.

e: added another ‘instead’ for consistency

1 Like

“Check” is slightly better on performance, but this isn’t really more flexible – it’s just harder to read and write. Stick with separate rules unless you have a clear reason to agglomerate them.

Really? I currently like one statement per room, but then again, I don’t have a mountain of code to sort through at present.

2 Likes

Inform supports a wide range of coding styles, and everybody has theirs. :) But the intent is small, separate rules. That’s what I recommend to newcomers.

1 Like

I also handle this “walking into the walls of a room” circumstance The Drew Way ™. It’s just so neat.

-Wade

3 Likes

I generally go with the “one check per room” rule, but yeah, the differences are pretty semantic. Whatever is neater for you.

It might be too fiddly or frou-frou to say:

a room has text called noway-text.

check going nowhere: if noway-text of location of player is not empty, say “[noway-text of location of player]” instead;

I have to admit I never tried “if going north” – instead I always said “if noun is north.” It hasn’t caused anything to blow up yet.

2 Likes