Hi im new here. I need some help with hats.

Hi I’m a student in a game design course in tafe and i really need help with my hat issue. I have tried to add hats into my game but every time i test it i can stick a hat on top of another hat with a hat all ready on my head. I really do not want this.

Example of code:
Instead of taking suspicious hat:
Say “You fling it on your head”;
Now the player is wearing suspicious hat.

How I tried to fix the hat problem:
Instead of wearing a hat when the player is wearing a hat:
Say “you have to take off the other hat first.”

I really don’t know how to fix it but i have tried. Can anyone help?

What’s going wrong is that the first rule fires when the action is taking the suspicious hat, while the second rule fires when the action is wearing the suspicious hat. (Note that the phrase “now the player is wearing the suspicious hat” does not start the wearing action: it just makes it so that it is the case that the player wears the hat.)

What you want is this:

  • Taking the suspicious hat leads to wearing it.
  • Wearing a hat is only possible when the player is not wearing another hat.

So we write:

Instead of taking suspicious hat:
try wearing suspicious hat.

Instead of wearing a hat when the player is wearing a hat:
say “you have to take off the other hat first.”.

(Untested, but I think it should work.)

I was hoping that you needed millinery sartorial advice, which as an owner of a great many hats I am well able to offer.

This is dangerous code because the wearing action includes an implicit take so you end up in an infinite loop.

I wouldn’t suggest converting taking a hat to wearing a hat because there is already an action for wearing, which responds to the command “wear hat”. However, you may want to hint that you can wear a hat when just taking it. Try this.

[code]“Test”

Report taking a hat:
say “You take [the noun]. You can also ‘wear [the noun]’ as well.”;
rule succeeds.

After wearing a hat: say “You fling [the noun] on your head.”.

Check wearing a hat when the player is wearing a hat (called the chosen hat): say “You have to take off [the chosen hat] first.” instead.

The Testing Room is A Room. A hat is a kind of thing. A hat is always wearable. The red hat is a hat in the testing room. The blue hat is a hat in the testing room.

Test me with “take red / take blue / drop red / drop blue / wear red / wear blue”.[/code]

Hope this helps.

PS. I believe this post should be under “Inform 6 and 7 Development” rather than “Getting Started and General Game Design”. If this is so, then can one of the wizards of this forum bestow the relevant magic on this post? Thanks.

Victor’s diagnosis is right, but part of his solution unfortunately won’t work. When you try to wear something you’re not holding, Inform by default has you automatically try to take it first. But then the “instead of taking the hat” rule redirects us to wearing the hat, and Inform has you automatically try to take it first, and… we get an infinite loop.

We can fix this by changing “Instead of taking the suspicious hat: try wearing the suspicious hat” to

After taking the suspicious hat: try wearing the suspicious hat.

That lets you pick up the hat normally, and then has you try to put it on after you’ve picked it up.

[On preview: climbingstars has already said the same thing, and I agree with him that you might just want to leave “take hat” so the player can pick up a hat without wearing it. But if you want to automatically wear a hat when you pick it up, this should work.]

Most hatters recommend that you always pick up a hat by the brim (preferably with both hands). Handling the crown may eventually wear through the felt. And remember: Next week (I believe its May 15) is National Straw Hat Day.

Robert Rothman

This lesson I have learned the hard way :frowning:

Never heard of that one before.

Well, at least you can’t go wrong with a straw dog! :slight_smile:

Thanks for all the help. Sorry i only got to this now. I will test them all and once again thanks.