Asking NPCs to perform multiple object actions

I have (finally and with lots of help from you folks) made my multiple object action for combining things work…

kitchen
You can see Bob and three apples here.

>combine 3 apples
You combined an apple, an apple and an apple and made an applesauce!

>look
kitchen
You can see an applesauce and Bob here.

… but it only works for the player. When I try to instruct an NPC to use it, the results are not right.

kitchen
You can see Bob and three apples here.

>bob, combine 3 apples
apple: apple: apple: >look
kitchen
You can see Bob and three apples here.

I tried looking in the documentation and the standard rules, but I haven’t figured it out yet.

There is a lot of stuff here, sorry it’s so much but this is a very complicated action. You will also need https://github.com/i7/extensions/blob/master/Brady%20Garvin/Object%20Kinds.i7x

Include Object Kinds by Brady Garvin.

Combining is an action applying to one thing. Understand "combine [things]" as combining.

The announce items from multiple object lists rule does nothing when combining.

Combining-valid-items is initially false.

Combining-items is initially false.

Combining-success is initially false.

Every turn while combining-valid-items is true or combining-items is true or combining-success is true:
	now combining-valid-items is false;
	now combining-items is false;
	now combining-success is false;

Before combining: if combining-items is true, stop the action.

The combining action has a list of objects called L.
The combining action has a list of texts called text-L.
The combining action has a table name called combining-table.

Table of No-Combinations
components list	result
{"nothing"}	"nothing"

Setting action variables for combining:
	now combining-table is table of no-combinations;
	now L is the multiple object list;
	repeat with text-shunt running through L:
		add "[the singular of the object kind of text-shunt]" to text-L;
	sort text-L;

Carry out combining when combining-valid-items is true (this is the combining main rule):
	now combining-items is true;
	repeat through combining-table:
		let x be a list of texts;
		now x is the components list entry;
		sort x;
		if text-L is x:
			now combining-success is true;
			repeat with y running through things in the prop-room:
				if "[the singular of the object kind of y]" exactly matches the text "[result entry]", case-insensitively:
					now y is in the location;
					say "[The actor] combined [L with indefinite articles] and made [a y]!";
					repeat with used running through L:
						now used is in the prop-room;
					break;
			break;

Carry out combining (this is the combining invalid items rule):
	if combining-success is false:
		now combining-items is true;
	
The combining invalid items rule is listed last in the carry out combining rulebook.

Report combining something (this is the report combining failure rule):
	if combining-success is false:
		if combining-items is true:
			say "The interaction between the cosmos and [regarding the actor][possessive] will is over-extended for producing that result in the current timeframe of [regarding the actor][possessive] existence.[paragraph break]";
		otherwise:
			if the multiple object list is empty:
				say "A combination requires a minimum of two things. Note that using the plural form of a noun is not sufficient. You must specify the quantity in a specific syntax, as in 'combine 3 apples' or 'combine 2 apples and 1 pear,' not simply 'combine apples' or 'combine apples and pears.'";
			otherwise:
				say "[The actor] can't seem to find a useful way to combine [L with indefinite articles].[paragraph break]";
			stop the action;

First every turn:
	now combining-valid-items is false;
	now combining-items is false;
	now combining-success is false;

The prop-room is a room.

An applesauce is a kind of thing.

1 applesauce is in the prop-room.

The kitchen is a room.

The player is in the kitchen.

Bob is a person in the kitchen.

A persuasion rule:
	persuasion succeeds;

An apple is a kind of thing.

3 apple are in the kitchen.

Check an actor combining (this is the combine apples rule):
	repeat with x running through L:
		if x is an apple:
			now combining-valid-items is true;

Actually, don’t look at this right now… darnit… I tried to extract this from my overall framework to make it even slightly shareable, and it is broken what I shared. I’ll try to post a working one later…

Don’t all your rules for combining need to be “an actor combining”? Sorry if this is all wrong but that seems like the obvious thing to look at.

Also on a quick test I think “The announce items from multiple object lists rule does nothing when an actor combining” should work, though it reads ugly.

Thank you! Adding “an actor” fixed the core issue.

The other problem with what I posted above was caused by me pasting an older version from one of my internal builds (whoops). Now that that is fixed, this works, except that suppressing the announce item rule doesn’t work for the other actors yet. I’ll still fiddle with it too, but if anyone can think of why what matt w said above (this first bit of code) doesn’t work, please let me know.

The announce items from multiple object lists rule does nothing when an actor combining.
You can see Bob and three apples here.

>bob, combine 3 apples
apple: Bob combined an apple, an apple and an apple and made an applesauce!

apple: Bob is unable to do that.
apple: Bob is unable to do that.

And here is the modified code that works (except for the announce item rule still happening):
[rant][code]
Include Object Kinds by Brady Garvin.

Combining is an action applying to one thing. Understand “combine [things]” as combining.

The announce items from multiple object lists rule does nothing when an actor combining.

Combining-valid-items is initially false.

Combining-items is initially false.

Combining-success is initially false.

Every turn while combining-valid-items is true or combining-items is true or combining-success is true:
now combining-valid-items is false;
now combining-items is false;
now combining-success is false;

Before combining: if combining-items is true, stop the action.

The combining action has a list of objects called L.
The combining action has a list of texts called text-L.
The combining action has a table name called combining-table.

Table of No-Combinations
components list result
{“nothing”} “nothing”

Setting action variables for combining:
now combining-table is table of no-combinations;
now L is the multiple object list;
repeat with text-shunt running through L:
add “[the singular of the object kind of text-shunt]” to text-L;
sort text-L;

Carry out an actor combining when combining-valid-items is true (this is the combining main rule):
now combining-items is true;
repeat through combining-table:
let x be a list of texts;
now x is the components list entry;
sort x;
if text-L is x:
repeat with y running through things in the prop-room:
if “[the singular of the object kind of y]” exactly matches the text “[result entry]”, case-insensitively:
now y is in the location;
say “[The actor] combined [L with indefinite articles] and made [a y]!”;
repeat with used running through L:
now used is in the prop-room;
now combining-success is true;
break;
break;

Carry out an actor combining (this is the combining invalid items rule):
if combining-success is false:
now combining-items is true;
now combining-success is false;

The combining invalid items rule is listed last in the carry out combining rulebook.

Report an actor combining something (this is the report combining failure rule):
if combining-valid-items is true and combining-success is false:
say “The interaction between the cosmos and [regarding the actor][possessive] will is over-extended for producing that result in the current timeframe of [regarding the actor][possessive] existence.[paragraph break]”;
if combining-valid-items is false:
if the multiple object list is empty:
say “A combination requires a minimum of two things. Note that using the plural form of a noun is not sufficient. You must specify the quantity in a specific syntax, as in ‘combine 3 apples’ or ‘combine 2 apples and 1 pear,’ not simply ‘combine apples’ or ‘combine apples and pears.’”;
otherwise:
say “[The actor] can’t seem to find a useful way to combine [L with indefinite articles].[paragraph break]”;
stop the action;

After printing a parser error while the player’s command includes “combine”:
say “[line break]You may also have been attempting to combine objects, but the syntax of the command was invalid. A combination requires a minimum of two things. Note that using the plural form of a noun is not sufficient. You must specify the quantity in a specific syntax, as in ‘combine 3 apples’ or ‘combine 2 apples and 1 pear,’ not simply ‘combine apples’ or ‘combine apples and pears.’ Of course, if you used the correct syntax, then again, either no such thing is present, or it is of little consequence.”;

First every turn:
now combining-valid-items is false;
now combining-items is false;
now combining-success is false;

The prop-room is a room.

An applesauce is a kind of thing.

1 applesauce is in the prop-room.

The kitchen is a room.

The player is in the kitchen.

Bob is a person in the kitchen.

A persuasion rule:
persuasion succeeds;

An apple is a kind of thing.

3 apple are in the kitchen.

Check an actor combining (this is the combine apples rule):
repeat with x running through L:
if x is an apple:
now combining-valid-items is true;
now the combining-table is table of applesauce making;

Table of Applesauce Making
components list result
{“apple”,“apple”,“apple”} “applesauce”
[/code][/rant]

Actually, I think the 2 “Bob is unable to do that” are from a different rule. This stems from the fact that the action is being tried on each item instead of on the list of items… but it is interacting with the carry out requested actions rule, not the announce multiple items rule, so this takes care of the second 2 error messages:

The carry out requested actions rule does nothing when combining-valid-items is true.

However, the first one still says “apple: Bob combined an apple, an apple and an apple and made an applesauce!” which I don’t want. This works, but is too extreme and messes up other rules:

The announce items from multiple object lists rule is not listed in any rulebook.

It proves the problem is there. But again, this doesn’t do the trick:

The announce items from multiple object lists rule does nothing when an actor combining.

Ah, you also have to add “The announce items from multiple object lists rule does nothing when asking someone to try combining.” It’s probably a good idea to leave the other one as “when an actor combining” in case you ever have “Try Bob combining…” directly in the source code.

(Do you know about the “actions” debugging command? That’s what I wound up using to track this down.)

Sorry for the misleading advice before – I had tested “when an actor” on a Before rule instead of an action-processing rule, which is I guess after the action gets turned from “asking someone to try…” to the action itself.

I was not familiar with that one (the action tracing), but I am more now, thank you.

Yay, this is now 99% done… just a little logic error on the reporting failure rule, but nothing I won’t be able to puzzle out myself. Thank you!