I7 'with' vs. 'and'?

Having a bit of trouble with commands - any help or pointers muchly appreciated. I have two commands (‘attach’ and ‘combine’). Both are activities applying to two things. Both have lines like the following:

Understand "attach" as something new.
Understand "attach [something] with [something]" as attaching it with.
Understand "attach [something] and [something]" as attaching it with.
Understand "attach [something] to [something]" as attaching it with.

Attaching it with is an action applying to two things.

(etc)

My problem is the following. “attach x to y” works. “attach x with y” works. “attach x and y”, however, generates the following error: “You can’t use multiple objects with that verb.”

Uh? Any hints accepted. Thanks!

That’s because ‘and’ is already parsed with a meaning that takes priority over your defined phrase, for commands like this:

>take cup and headphones and book and stuffed alligator

So when you use ‘and’ as a conjunction, Inform thinks that you’re trying to perform the same, single-noun action on many distinct nouns. (It thinks you’re trying to attach x, then attach y.)

You can totally intercept a multiple single-noun action and get it to behave differently - for example, by redirecting it to a single two-noun action -, although it’s one of the weirder parts of Inform, and may take a little while to get your head around. The Left Hand of Autumn is the right place to start.

This is because the Inform Parser thinks you mean “attach x” then “attach y” in the same way “take x and y” means “take x” then “take y”. It mistakes the command for a multiple action. If you don’t have any multiple actions, you can fix this by adding this line.

Include (- -) instead of "Parse Token Letter E" in "Parser.i6t".

Hope this helps.

Ahhh. I knew there was an answer I just hadn’t found. Many thanks, folks.

OK, I found that example. I’m a bit confused - it uses something like ‘let L be the list of matched things;’ but Inform breaks and says it doesn’t know what that is. Example 356 has a definition plus complex i6 embedding which purports to construct a list of matched things. Is that what Left Hand assumes you’re doing? Or should that list be a predefined one?

Anyway, still no go. :slight_smile: Using just ‘understand “attach [things]” as attaching it to’ changes the error message to:

“You must supply a second noun. (line break) You must supply a second noun.” Indicating that all that does is try to run multiple single-noun commands. AIGH. This is making me nuts…and I came down this rabbit hole because having ‘attach x to y’ and ‘attach x and y’ act differently was jarring…

I got the Ex. 356 thing (def. plus i6) to at least not pitch errors, but it behaves just as if I’d only used the ‘attach [things]’ construct - same double error message.

Have you included all of the example? It’s broken up a bit by explanations: there should be some stuff a little bit lower down:

The silently announce items from multiple object lists rule is listed instead of the announce items from multiple object lists rule in the action-processing rules. This is the silently announce items from multiple object lists rule: unless multiply-examining or multiply-examining something from something: if the current item from the multiple object list is not nothing, say "[current item from the multiple object list]: [run paragraph on]". Definition: a thing is matched if it is listed in the multiple object list.
That should let Inform know what ‘matched’ means, and therefore what the list of matched things is. (Though you’ll need to change ‘multiply-examining’ to whatever your new action is.)

As I warned you, this is pretty brain-twisting stuff, and if you don’t feel like stretching your coding muscles a bit, I advise that you take climbingstars’ approach or else get rid of the ‘attach X and Y’ syntax entirely.

Assuming you want to go down this rabbit-hole, your problem is that you’re redirecting [things] to an inappropriate action. ‘Attaching’ is still an action on two nouns, but ‘attaching [things]’ isn’t one action on an indefinite list of nouns: it’s an indefinite number of actions, each on a different noun. There’s never any second noun involved, just as ‘take all’ is just a bunch of individually-resolved taking actions.

So what you need is a separate action:

And-attaching is an action applying to one thing. Understand "attach [things]" as and-attaching.

It’s not, really, but the parser understands it as though it is; so now we’re going to redirect it:

[code]Group-attach-complete is a truth state that varies.

Check and-attaching when group-attach-complete is true:
stop the action.[/code]
If you don’t do this bit, it’ll try attaching for every item you mention. (The next section kind of cheats by making the first attempted action do everything, then stopping the other actions from resolving.)

[code]Carry out and-attaching:
let L be the list of matched things;
if the number of entries in L is 0, say “You should specify the things you want to attach.”;
if the number of entries in L is 1, say “You’d have to attach it to something in particular.”;
if the number of entries in L > 2, say “You can only attach two things together at a time.”;
if the number of entries in L is 2:
let X be entry 1 in L;
let Y be entry 2 in L;
try attaching X with Y;
say line break;
now group-attach-complete is true.

Before reading a command:
now group-attach-complete is false.[/code]
(Code not tested. May take a little tweaking to work ideally.)

Hmmmmm I think I see. Okay! TO BATTLE WITH CUT AND PASTE and hopefully to learn. Thanks much (again) will report back!

Thanks very much to all, especially to maga! I got it working. I had a bit of an issue; when handling multiple object lists, there’s a standard rule to list each object before executing the command’s rules. So, although the first run through was properly setting the group-attach-complete flag, it was still listing all the items in the output. I had to override that rule, layering it with one that checked if we were doing the and-attaching action (if so, stay silent, otherwise, do like normal). Wanted to post the final code as it’s working. The announcement rule override comes first.


The carefully announce items from multiple object lists rule is listed instead of the announce items from multiple object lists rule in the action-processing rules.

This is the carefully announce items from multiple object lists rule:
	if and-attaching:
		do nothing;
	otherwise:
		abide by the announce items from multiple object lists rule.

Definition: a thing is matched if it is listed in the multiple object list.

And-attaching is an action applying to one thing.  Understand "attach [things]" as and-attaching.

Group-attach-complete is a truth state that varies.

Check and-attaching when group-attach-complete is true:
	stop the action.
	
Carry out and-attaching:
	let L be the list of matched things; 
	if the number of entries in L is 0, say "You should specify the things you want to attach."; 
	if the number of entries in L is 1, say "You'd have to attach it to something in particular.";
	if the number of entries in L > 2, say "You can only attach two things together at a time.";
	if the number of entries in L is 2:
		let X be entry 1 in L;
		let Y be entry 2 in L;
		try attaching X with Y;
	say line break; 
	now group-attach-complete is true.

Before reading a command: 
	now group-attach-complete is false.

Attaching it with is an action applying to two things.

Understand "attach [something] to [something]" as attaching it with.

Check attaching it with:
	if the second noun is nothing, say "You need two things." instead.
Carry out attaching it with:
	say "Attaching [the noun] with [the second noun]!"

Nice work! Messing with multiple actions gave me a thorough headache the first time I delved into it, so well done you for persisting.

You can also write this bit like this.

This is the carefully announce items from multiple object lists rule: unless and-attaching, abide by the announce items from multiple object lists rule.