Actions with two arguments: a number and a thing

I’m not sure this is possible (directly) with Inform, but here is what I want to do:
I want to buy a number of the same kind of things, say “BUY 6 ARROWS”. Since BUY is a reserved (and blocked) action, I use PURCHASE for now.

Purchasing is an action applying to one number and one thing.
Understand "purchase [number] [something]" as purchasing.

Carry out purchasing:
	say "You asked to buy [number] [noun]";
	say "Ganon has [qty of noun] of these. ";

I get this error:

**Problem.** You wrote 'say "You asked to buy [number] [noun]"',
but 'number' is used in a context where I'd expect to see a (single)
specific example of a sayable value, not a description.

It seems that the action parser cannot handle these two arguments, or I don’t know how to reference them in the CARRY OUT PURCHASING rule.

I have an alternative option to BUY ARROWS, then ask how many arrows the player wants. I can use the QUESTIONS extension, but that has its problem too.

I know I can use this construct to TAKE 6 ARROWS successfully, so how did the developers do it?

I would think this is a fairly straightforward question, and action. Can someone offer advice?

You can get part of the way there:

lab is room. There are 7 balls in the lab.

Purchasing some of is an action applying to one number and one thing.
Understand "purchase [number] [something]" as purchasing some of.

Carry out purchasing some of:
	say "You asked to buy [number understood] [second noun]";

However, if you type purchase 5 balls, you get the response You asked to buy 5 7 balls. Someone else may know how to get past that.

This error has nothing to do with your action – it’s telling you that say "[number]" is impossible because it takes number to mean any number, but that’s not valid in say - you need to choose a specific number. You might be able to use [number understood] (as in rileypb’s code), but I’m not sure if that works here.

1 Like

For this case, you don’t try to separately parse the number and the thing. You use the [things] token in the grammar to indicate that it applies to multiple objects (even though the action specification itself refers to applying to one thing).

lab is room.

ball is a kind of thing.

There are 7 balls in the lab.

understand the command "buy" as something new.

multiple-buying is an action applying to one thing.
Understand "buy [things]" as multiple-buying.

carry out multiple-buying: try taking the noun.
2 Likes

The easiest thing is probably just to let the purchase action apply to multiple objects:

Understand "purchase [things]" as purchasing.

You might want to do some work around the output to avoid spamming the player with 12 different identical responses, or catch if they player’s trying to buy more items than are available.

EDIT: Ninja’d by Zed!

1 Like

Consolidated Multiple Actions by John Clemens provides an excellent solution to this… and there’s a bug in 10.1 that means it can’t work there. (The big has been fixed in the current development version.) So, someday…

2 Likes

Is there any difference between the “Purchasing some of” action and the “Purchasing” action?

I don’t get it. Using your code, it all compiles but whatever I try to buy,
I get an “You can’t see any such thing.” response.
I can buy one of something, e.g. “Buy leather armor” but cannot buy something if a number precedes the item.

No, I don’t suppose – I was trying to make it match the typical phrasing of a two-noun action: poke it with, but it doesn’t really work in this case, since you can’t do something like:

Carry out purchasing 5 of something:

I think I’d suggest flipping it so the number is the second argument.

Purchasing it in quantity is an action applying to one thing and one number,
Understand "purchase [number] [thing]" as purchasing it in quantity (with nouns reversed).

Actually, I didn’t need to do either of those. I7 takes care of handling duplicates.
(It didn’t work before because I was not in a room with duplicates. :roll_eyes:

Understand the command "buy" as something new.
Multiple-buying is an action applying to one thing.
Understand "buy [things]" as multiple-buying.

Carry out multiple-buying:
	try taking the noun;

I get this response:
/> buy 3 arrows
arrow: taken.
arrow: taken.
arrow: taken.

Which is what I want. I will handle the repeated reporting part next.

2 Likes