Matching Values to Variables?

How do I match different kinds of text, and if I can’t do that, how do I convert them both to just being text?

What I’m hoping to do is make the player USE the spyglass to go in the correct direction. (The spyglass itself works fine, as it generates a new, random thwy every time I USE it.) Once the player does that five times (as counted by STally), they’re moved to the destination (pre-Revenge).

The problem is that “the way” is a temporary named value holding a direction, while “thwy” is a non-temporary variable holding a direction. It can’t identify when the player input (as a direction, since if they type “N” i obviously want that to match “north”) matches the direction randomly picked when the spyglass is used. I tried to clumsily fix it by converting the way to a new variable called rte, but that didn’t work. I’m so sure there’s an easier way to convert a variable into a value or vice versa, or at least to convert them both into text, but I don’t know how.

Here is the relevant code:

Thwy is a direction that varies.

Check spying:
	if the noun is the spyglass:
		if the location is not nautical:
			say "You bring the device up to your eye, but everything appears too large and blurry. This isn't the place to use it.".

Carry out spying:
	if the location is The Revenge:
		say "The Republic of Pirates is naught but a distant blob of land.";
	if the location is Ocean:
		let thwy be a random earthbound direction;
		if thwy is not nothing:
			say "[one of]You put the spyglass to your eye. The familiar shape of a large custom-built ship is to the [thwy].[or]You squint through the spyglass. The Revenge drifts [thwy]ward.[then at random]".
STally is a number that varies.
Instead of going a direction (called the way) when the player is in Ocean:
	if STally is at least 5:
		move the player to pre-Revenge;
	if STally is less than 5:
		if the way matches thwy:
			say "Putting your shoulders into it, you confidently row towards the ship.";
			increment STally;
			now thwy is southwest;
			stop the action;
			say "You paddle aimlessly.";
			stop the action.

You can assign to a global variable like thwy by writing: now thwy is a random direction;.
If two variables hold directions, you can compare them directly using “if ... is ...”. It doesn’t matter in that case if the player types abbreviations like “N” for “NORTH”.

Here’s a simplified example:

Rightway is a direction that varies.

The Ocean is a room.

Coconut Island is south of the Ocean.

Banana Island is west of the Ocean.

When play begins:
	now rightway is south;

Instead of going a direction (called the way) when the player is in Ocean:
	if the way is rightway:
		say "Yep, that's the right way.";
		continue the action;
		say "You don't think that's the right way.";



You don’t think that’s the right way.

You don’t think that’s the right way.

Yep, that’s the right way.


That worked like a charm!! Thank you so much :smiley:

1 Like