Oh Mercy. Player "makes" something formerly nonexistent?

OK, I thought I had this one whipped but then I saw some really stupid bugs.

I defined a word “make”:

Making is an action applying to one thing. Understand "make [something]" as making.

I want the player to be able to make a hat when he has collected the materials to make it with. Since it matters what you make, I have to have “applying to one thing”. But if there isn’t already a hat in the room, then “make hat” results in “you can’t see any such thing” even before it applies my custom commands.

So I tried putting an invisible hat in the room (scenery). A stupid hack, I know. That resulted in me having to write a lot of “instead” code so that if you try to take or examine or wear it, “You can’t see any such thing.”

Then I discovered the insurmountable problem: That means you can’t make the hat when you’re in another room.

I guess I could put the hat on the player and try to make it invisible, but this all feels like a really stupid way to proceed.

Relatedly, I’d prefer it if “make dinosaur” or even “make lsdkjfladksj” resulted in “You don’t know how to make that” rather than “You can’t see any such thing.” Why should you have to see it to try to make it?

As always, any advice would be appreciated.

Try defining your action as applying to a topic instead of a thing:

Making is an action applying to one topic. Understand "make [text]" as making.

Then you’ll have rules like:

Carry out making "hat": [etc]

The quotation marks around “hat” in that rule tell Inform that it’s a topic it’s dealing with, not a thing. The tricky bit here is making sure that any word the player can use to refer to the hat also works when making the hat. You might try something like:

[code]Understand “hat/sombrero” as “[hat-names]”.
Understand “[hat-names]” as the hat.

Carry out making “[hat-names]”: [and so on][/code]

That solves both your problems: the hat doesn’t have to be around when the player makes it (because MAKE HAT doesn’t actually refer to the hat, only to a hat topic), and you can easily add a “Check making” rule to catch attempts to make non-hat things.

That’s one method; here’s another for comparison. You can act on objects out of play using a two-fold process. First, you define the action as applying to a visible thing. “Visible” here means “in scope” which usually means the player can see it, but not necessarily touch it. Then use the the word “[any …]” in the grammar definition. This puts any object of that description (including ones the player can’t see) into scope for the purposes of that action. (See ex. 265 “Introduction to Juggling”)[code]A thing can be makeable.

Making is an action applying to one visible thing.
Understand “make [any makeable thing]” as making.
[/code]Now Inform will understand the make command for anything you define as makeable. Next you wanted to change the error message:Understand "make [text]" as a mistake ("You don't know how to make that."). Now any text (including object names) that aren’t makeable things will fall here.
Now I just added a list of objects for the parts and a simple check, carry out and report rule (you might need to redo the tabs when pasting this code):[code]A thing has a list of objects called the needed parts.

Check making:
let has-parts be true;
repeat with item running through the needed parts of the noun:
if the player does not enclose the item:
now has-parts is false;
break;
if has-parts is false, say “You don’t have all the necessary components on you.” instead.

Carry out making:
repeat with item running through the needed parts of the noun:
now item is in limbo;
now the player carries the noun.

Report making:
say “After a little work, you make a spiffy new [noun].”

[/code]Finally the scenario:[code]The Lab is a room. Some felt is in the Lab.
North of the lab is the Back. A band is in the Back.

Limbo is a container. The hat is a makeable wearable thing in limbo. The needed parts is {some felt, the band}.

test me with “make gumbo / make felt / get felt / make hat / n / make hat / get band / make hat / wear it / i.”[/code]Of course that would still need to be fleshed out. Also, check out examples 309 and 402, which deal with making a shirt and a fishing pole respectively.

I suggest you go with Mike’s code. His is much more elegant than mine! :slight_smile:

Hm, Emerald, my first impuse was to go with yours, just because it seemed more immediately familiar.

I need some time to absorb both ideas and figure it all out. Thanks so much to both of you!

After looking all this over, I see that Mike’s code is more versatile and more correct.

But for this game I do consider using Emerald’s, only because the player is going to make one thing, from one material, and call it by one name. Also, this game is a Christmas present to my husband :slight_smile: , and quicker might be better this round. If I get done early I’ll go back and improve things that could have been done better.

Question, though, if I use Emerald’s way: How do I handle the attempted making of non-hats?

This code:

[code]Carry out weaving “hat”:
If the player is carrying the fibers
Begin;
say “You weave the fibers into a crude hat. It looks terrible, but it’s serviceable.”;
remove fibers from play;
move hat to player;
Otherwise;
say “You don’t have anything to weave with.”;
End if.

Carry out weaving:
say “You don’t know how to make that.”.[/code]

Causes me to get both messages after weaving the hat. Switching the order, using “check”, and other such things seems to either get me both messages or only the latter.

[Edited to remove a bad syntax example, which it turns out didn’t have much to do with my problem]

When an action is being run, all the applicable check and carry out rules run in order. The reason you get both messages is because both rules should fire when you type “weave hat”. “Carry out weaving ‘hat’” fires when the topic understood is “hat” and “carry out weaving” fires whenever the action is “weaving” (regardless of topic).

Actually, the example you edited out is closer to correct, but has a few problems. First, the variable the topic is put into is called “topic understood” (not “topic”). Second, since the topic understood is a snippet, you have to use “matches” to compare it to quoted material. Third, if you want to have a check rule which ends the action, you end it with “instead.” Fixing those leaves you with:Check weaving: if the topic understood does not match "hat", say "You don't know how to weave that." instead. … which works, but still has a slight problem. You see, when working with topics, Inform matches the snippet exactly. It makes no assumptions about articles, etc. like it would with an object. In other words, with the code above, coupled with your “Carry out weaving “hat”:” rule, you end up with this output:

This can be fixed by using a text substitution, as Emerald suggested up-thread. This leaves you with something like:[code]Understand “hat/cap” and “a/the hat/cap” as “[hat-names]”.

Check weaving:
if the topic understood does not match “[hat-names]”,
say “You don’t know how to weave that.” instead.

Carry out weaving “[hat-names]”:
…[/code]
Edit: Strictly speaking, you don’t have to use “matches” when dealing with snippets; you could also use “includes” (see ch. 17.31). :slight_smile:

Ergh! What am I doing wrong?

[code]Weaving is an action applying to one topic.
Understand “weave [text]” as weaving.

Understand “hat/a hat/the hat/straw hat/a straw hat/the straw hat/fiber hat/a fiber hat/the fiber hat” as “[hat-names]”.

Carry out weaving “[hat-names]”:
If the player is carrying the fibers
Begin;
say “You weave the fibers into a crude hat. It looks terrible, but it’s serviceable.”;
remove fibers from play;
move hat to player;
Otherwise;
say “You don’t have anything to weave with.”;
End if.

Check weaving:
if the topic understood does not match “[hat-names]”,
say “You don’t know how to weave that.” instead.[/code]

This gets me:

[code]

weave hat
You don’t know how to weave that.

weave a hat
You don’t know how to weave that.

weave sdlkfjs
You don’t know how to weave that.

take fibers
Taken.

weave hat
You don’t know how to weave that.

weave straw hat
You don’t know how to weave that.[/code]

Same result if I swap the positions of carry out and check, or if I use “include” instead of “match.”

It’s this line:

Understand "hat/a hat/the hat/straw hat/a straw hat/the straw hat/fiber hat/a fiber hat/the fiber hat" as "[hat-names]".

The slash can only be used to separate alternative words, not alternative phrases. If you do it this way it should work:

Understand "hat" or "a/the hat" or "straw/fiber hat" or "a/the straw/fiber hat" as "[hat-names]".

Yay, it works! I even briefly thought about the fact that I didn’t fully understand the structure in that statement, and then promptly forgot.

Thanks so much, you two know everything!

“Make” is cool. It would be fun to use in another game, with the other code, where a number of things could be made from a number of items.

Thanks again.