Matching inventory items with parent kind

I want to match a property of an item with inventory with a property being bought.
The property is the PID of the parent kind. The player can not buy a second PID if he/she already has one. For example, if the player already has armor (PID = 100), the player cannot buy another one. There are many kinds of armor, but all have PID = 100.

This is the check purchase rule:
	say "Noun is [noun]. It has a PID of [PID of noun][line break]"; 
	if noun is not purchasable:
		stop the action;
	if player has PID of something with PID of noun:
		say "You already have [the noun]. You can't wear another one, and it's too bulky to carry around with you.";
		stop the action;

The parser flags my line if player has PID of something with PID of noun: but I don’t know what works.Any advice in phrasing?

I guess, in general, I don’t know how to search through inventory. Do I use a loop to traverse inventory, or “contents of inventory” or “list of inventory”? Inform seems to be smart enough to know inventory is a list.

This uses some fancy Inform features, but I think it’s the most elegant way:

Matching relates a thing (called X) to a thing (called Y) when the PID of Y is the PID of X.
The verb to match means the matching relation.

...
if the player encloses something (called the alternative) that matches the noun:
    say "You already have [the alternative]." instead.
...
1 Like

I revised my code, but these statements give me a parsing error.

Error: In the sentence ‘if the player encloses something (called owned) that matches the noun’, I was expecting to read a value, but instead found some text that I couldn’t understand - ‘player encloses something (called owned) that’.

I was trying to match one of these phrases:

  1. (player encloses something ( called owned ) that - value) matches (noun - description of values)
  2. (player encloses something ( called owned ) that - snippet) matches (noun - topic)
    I recognised:
    noun = a non-temporary variable, holding an object
    But I didn’t recognise ‘player encloses something ( called owned ) that’.

Your code inserted into my code is

[Set parent-child relationship.]
Matching relates a thing (called X) to a thing (called Y) when the PID of X is the PID of Y. 
The verb to match means the matching relation.

This is the check purchase rule:
	say "Noun is [noun]. It has a PID of [PID of noun][line break]"; 
	if noun is not purchasable:
		stop the action;
	if the player encloses something (called owned) that matches the noun:
		say "You already have [owned]. You can't wear another one, and it's too bulky to carry around with you.";
		stop the action;

Oh, shoot, right, “matches” is a reserved word. Change that to “aligns with” or something else.

What does “matches” actually do? Could it be what I need?

I used these lines of code:

Pairing relates a thing (called X) to a thing (called Y) when the PID of X is the PID of Y. 
The verb to pair means the pairing relation.

Interestingly, “pairing with” did not work, and “encloses” in the check did not work, but

	if the player has something (called owned) that pairs the noun:

did.

Thanks, Hidnook, but I don’t know the actual name of the item during the action.

Text matching

if "[score]" matches the text "100"

if "[score]" exactly matches the text "[best score]"

number of times "xyzzy" matches the text "Z", case insensitively

1 Like