I7: Spaghetti Code

Hi all,

I’ve put together some sick spaghetti code:

At the time when the autokommt timer clucks:
	say "[if MFZ flag is 1]Far to the southeast you see a car approaching.[end if][if MFZ flag is 2]The car approaches quickly. It's a blue VW Passat Kombi.[end if][if MFZ flag is 3]The Passat stops right beside you! The driver waves you to hop in. Hooray, a free ride![end if]";
	if MFZ flag is 3, now the VW Passat is in At the Bus Stop;
	now MFZ flag is MFZ flag plus 1;
	if MFZ flag is 2, the autokommt timer clucks in two turns from now;
	if MFZ flag is 3, the autokommt timer clucks in two turns from now.

While it works as intended, I’m lacking understanding for some concepts that would have helped me. Could you perhaps advise me how I should have written this?
1.) As for the “say” command, how could I avoid this if-then-if-then code? I don’t want to cycle the text as I want to play with the flag later on - I’m rather looking for the equivalent to “switch” from Inform 6.
2.) When I wrote “if MFZ flag is smaller than 4” I got a compiler error message. Why is that so?

Thanks and kind regards,

Grue

See chapter 11.8. in the manual.

The phrase you’re looking for is “if MFZ flag is less than 4”.

Your code is not horribly tangled as it is, but one way to make it cleaner (and to eliminate the MFZ Flag global variable altogether) would be to break it into three separate timed events:

at the time when Passat enters view:
	say "Far to the southeast you see a car approaching.";
	Passat approaches stop in two turns from now;

at the time when Passat approaches stop:
	say "The car approaches quickly. It's a blue VW Passat Kombi.";
	Passat reaches stop in two turns from now;

at the time when Passat reaches stop:
	say "The Passat stops right beside you! The driver waves you to hop in. Hooray, a free ride![end if]";
	now the VW Passat is in At the Bus Stop;

Or you could do something like this:

[code]Bus Stop is a room.

VW Passat Combi is an enterable container. Passat has a number called distance. The distance of Passat is 100.

When play begins: now the distance of Passat is 5.

Definition: Passat is approaching if the distance of Passat is greater than 0 and the distance of Passat is less than 6.

Every turn when Passat is approaching:
decrement the distance of Passat;
If the distance of Passat is:
– 4:
say “Far to the southeast you see a car approaching.”;
– 2:
say “The car approaches quickly. It’s a blue VW Passat Kombi.”;
– 0:
say “The Passat stops right beside you! The driver waves you to hop in. Hooray, a free ride!”;
now Passat is in the location;[/code]
There’s no advantage to that if you just want to print out some messages, but if you wanted to put the car in scope while it’s approaching, for example, this might help.

[code]After deciding the scope of the player when Passat is approaching:
if examining, place Passat in scope.

Instead of examining the approaching Passat:
say “The approaching car is about [distance of Passat in words] kilometers away.”
[/code]