Help with stopping player from wearing conflicting clothing

This forum seems pretty dead, but just in case it isn’t, I was wondering if I could have some help with something.

I have a complex clothing system, each garment has a value for what layer of clothing it is, and where on the body it is being worn.
For example, if the player tries to wear something that was classed as both legwear and clothing, while already wearing a garment that has values of legwear and clothing, the attempt is stopped and they are told “You are already wearing a garment like this!”

Here is what I have so far:

[spoiler][code]Armortype is a kind of value. The armortypes are jewelry, clothing, covering, undergarment, and armor.

Wornlocation is a kind of value. The wornlocations are headwear, facewear, neckwear, chestwear, backwear, torsowear, waistwear, pelviswear, legwear, anklewear, footwear, armwear, wristwear, and handwear.

A garment is a kind of thing. A garment always has an armortype. A garment always has a wornlocation. Garments are wearable. The description of a garment is “It’s [wornlocation] [armortype].”

Bling is a kind of garment with armortype jewelry.

A basic shirt is a garment with armortype clothing and wornlocation torsowear.
basic pants are a garment with armortype clothing and wornlocation legwear.
basic shoes are a garment with armortype clothing and wornlocation footwear.
A green shirt is a garment with armortype clothing and wornlocation torsowear.

Before wearing a garment (called Y) when the player is wearing a garment:
repeat with item worn by the player:
if item armortype matches Y armortype and item wornlocation matches Y wornlocation:
stop the action and break.[/code][/spoiler]

I’m very new to inform 7, and I have no idea how to go about this. The things I’ve tried all cause compile errors, so I’m not sure how to reword my before statement to work right. I would rather not create separate rules for every combination of armortype and wornlocation. If anyone has tips, suggestions, or solutions, I would love to hear it! :smiley: :smiley:

(Bonus points if the conflicting clothing items are swapped instead of the wear command being canceled. Super duper bonus points if it asks if you want to swap clothes or cancel.)

This forum is far from dead! You’ll find lots of advice here.

On first glance, it looks like you’ve got the idea about processes but may not have them phrased how Inform expects.

Before wearing a garment (called Y) when the player is wearing a garment: repeat with item worn by the player: if item armortype matches Y armortype and item wornlocation matches Y wornlocation: stop the action and break.
Try this:

Before wearing a garment when the player is wearing a garment: repeat with Y running through garments worn by the player: if the armortype of the noun is the armortype of Y: say "Do you want to remove [the Y]?"; if the player consents: say "(You first remove [the Y])"; now the player carries Y; [this skips the normal action of removing worn things] otherwise: say "You decide not to swap [the noun] for [the Y] you are wearing."; stop the action; if the wornlocation of the noun is the wornlocation of Y: say "Do you want to remove [the Y]?"; if the player consents: try taking off Y; [using the action is good if you have any effects on taking off garments you want to run] otherwise: say "You change your mind about wearing [the noun]."; stop the action;
I think this will work - it’s off the top of my head but might need more tweaking.

“if the player consents” is a nifty and useful phrase that offers the player a yes/no choice.

A garment is a kind of thing. A garment always has an armortype. A garment always has a wornlocation. Garments are wearable. The description of a garment is "It's [wornlocation] [armortype]."

Again, not tested:

A garment is a kind of thing. A garment is wearable. Every garment has an armortype. The armortype of a garment is usually clothing. Every garment has a wornlocation. The wornlocation of a garment is usually torsoworn. The description of a garment is usually "It's [wornlocation] [armortype]."

“Usually” will give garments your default description here, but you have the option to specify it instead.

The fabulous helmet is a garment. The wornlocation of fabulous helmet is headworn. The armortype of fabulous helmet is armor. The description of the fabulous helmet is "Ooooh, sparkly!"

(I think I misread all the recent post dates as 2015 or smth, because I reread them and they all said 2017. My bad, this forum is super not dead. :laughing: )

Thank you so much! I had to modify it so that the if statements were nested, and now it works perfectly. :smiley: Thanks for setting me in the right direction! Here is my new code for when the player tries to wear a garment:

Before wearing a garment when the player is wearing a garment: repeat with Y running through garments worn by the player: if the armortype of the noun is the armortype of Y: if the wornlocation of the noun is the wornlocation of Y: say "Do you want to remove [the Y]?"; if the player consents: try taking off Y; [using the action is good if you have any effects on taking off garments you want to run] otherwise: say "You decide not to swap [the noun] for [the Y] you are wearing."; stop the action;

You might have been inadvertently taking the user’s “join” date (below their name) as the post date (which is on the right).

Glad I was able to help! :wink:

Just be aware - the way you’ve nested the if conditions, it won’t check “wornlocation” unless the “armortype” also matches. You may intend that, but it sounded like these were two separate conditions you wanted to check.

If you want them separate, you need to either write two separate rules (which is fine) or pull the second condition to check to the same indent level as an additional routine if the first one passes in the same rule.