Repeat Running Through

Hello, all:

I am trying to make it so that once you give any two items to the wizard then he will magically join them together. I’m not at the “join” part of coding this yet as I am stuck trying to determine when the wizard has two objects. The following code compiles but does not completely work:

`tmerlin is a man in Padded_Cell_Four.  "An old man in a purple robe and purple wizard's cap is standing here."  The description is "The old man is wearing a purple pointed wizard's cap and matching purple robe, both with stars and meteors on them.  He is gesturing and gesticulating at you as if casting a spell.  But, of course, there's no such thing as magic, not even in your subconscious, so when nothing happens the old man looks confused and turns to read from the wall.". the scent of Merlin is "You get the whiff of incense."  Merlin can be powerful or weak.  merlin is weak.

understand "wizard" as merlin.

instead of giving something to merlin when Merlin is weak:
		say "You hand Merlin the [noun].  He looks it over and tucks it into his belt.  He is looking at you expectantly.";
		now merlin has noun;
		now merlin is powerful

instead of giving something to Merlin when Merlin is powerful:
	say "You hand Merlin the [noun].";
	now merlin has noun;
	repeat with item running through the list of things carried by Merlin:
		now item is noun;
		repeat with item 2 running through the list of things carried by Merlin:
			now item 2 is noun;
			say "Merlin grins a wide grin as he studies [item] and [item 2].";
			stop the actionype or paste code here`

The results of the text box above is:

>give beef to merlin
You hand Merlin the a pound of ground beef.  He looks it over and tucks it into his belt.  He is looking at you expectantly.

>give margarine to merlin
You hand Merlin the a tub of margarine.
Merlin grins a wide grin as he studies a tub of margarine and a tub of margarine.

Give this a try:

Instead of giving something to Merlin when Merlin is weak:
	say "You hand Merlin [the noun].  He looks it over and tucks it into his belt.  He is looking at you expectantly.";
	now merlin carries the noun;
	now merlin is powerful;

instead of giving something to Merlin when Merlin is powerful:
	say "You hand Merlin [the noun].";
	now Merlin carries the noun;
	say "Merlin grins a wide grin as he studies [the list of things carried by Merlin].";
	stop the action;

This is assuming he’s only “weak” when he’s carrying nothing and “powerful” when he’s carrying exactly one thing.

1 Like

Thank you for your suggestion, I appreciate it.

The code I have written to join two items carried by Merlin (does not compile):

instead of giving something to Merlin when Merlin is powerful:
	say "You hand Merlin the [noun].[paragraph break]";
	now merlin has noun;
	say "Merlin grins a wide grin as he studies [the list of things carried by Merlin].  He begins gesturing and gesticulating again but this time his actions appear to have a purpose -- there is a soft glow coming from his hands when he picks up [the list of things carried by merlin] and they begin to glow as well as his hands.  Merlin waves his arms slowly, perhaps as stunned that it is working and the prospect of what the outcome might be.  Merlin clears his throat and yells, 'Join!'  There is a flash and when the smoke clears, Merlin hands you the item and smiles, more relieved than out of politeness.";
	repeat with item1 running through the list of things carried by Merlin;
	now item1 is noun;
	repeat with item2 running through the list of things carried by Merlin;
	now item2 is noun;
	now item2 is stuck to item 1;
	now item2 is part of item;
	now item is carried by player.

It’s rare that I can’t get something to compile at all, but there it is. I think there is some fundamentals about the repeat running through loop that I need to brush up on. Until then, any assistance is appreciated.

1 Like

When you said ‘it doesn’t compile at all’ I thought, ‘I wonder if he’s ending a loop line in a semicolon’, because that’s what usually does it for me.

And it looks like you are! You should end the ‘repeat with’ line with a colon, then indent everything afterwards that you want to be part of the loop.

1 Like

As always, thank you for your guidance. This worked immediately and should have been obvious to me. Thank you!

Now it will compile and when I run the program and give merlin two items I get the run-time error:

*** Run-time problem P15: You can't move nothing.

Is “item” defined elsewhere? I see item1 and item2 declared in the code but not item by itself, so trying to move it to the player in the last line might be the issue.

Also I’m a little confused by your loops, since you wouldn’t setting both item1 and item2 to the noun mean you’re not doing anything to anything Merlin is carrying except the last thing you handed over? Are there really just two items you want to incorporate into each other, or is there some more complex thing you’re trying to do?

Thanks, DeusIrae, for contributing. I defined item1 and item2 as:

item1 is an object that varies.
item2 is an object that varies

WIth this code I am just trying to stick the second item to the first by joining them. It’s just the two items, I’m not trying to do anything more complex.

That’s uncharacteristically bad grammar for Graham Nelson.

An update to the coding I have been doing: I have changed some wording and added some debugging code so that I can see what is going on. This is the code now:

merlin is a man in Padded_Cell_Four.  "An old man in a purple robe and purple wizard's cap is standing here."  The description is "The old man is wearing a purple pointed wizard's cap and matching purple robe, both with stars and meteors on them.  He is gesturing and gesticulating at you as if casting a spell.  But, of course, there's no such thing as magic, not even in your subconscious, so when nothing happens the old man looks confused and turns to read from the wall.". the scent of Merlin is "You get the whiff of incense."  Merlin can be powerful or weak.  merlin is weak.

understand "wizard" as merlin.

item1 is a thing that varies.

item2 is a thing that varies.

instead of giving something to merlin when Merlin is weak:
		say "You hand Merlin the [noun].  He looks it over and tucks it into his belt.  He is looking at you expectantly.";
		now merlin has noun;
		now merlin is powerful

instead of giving something to Merlin when Merlin is powerful:
	say "You hand Merlin the [noun].[paragraph break]";
	now merlin has noun;
	say "Merlin grins a wide grin as he studies [the list of things carried by Merlin].  He begins gesturing and gesticulating again but this time his actions appear to have a purpose -- there is a soft glow coming from his hands when he picks up [the list of things carried by merlin] and they begin to glow as well as his hands.  Merlin waves his arms slowly, perhaps as stunned that it is working and the prospect of what the outcome might be.  Merlin clears his throat and yells, 'Join!'  There is a flash and when the smoke clears, Merlin hands you the item and smiles, more relieved than out of politeness.";
	repeat with item1 running through the list of things carried by Merlin:
		now item1 is noun;
	repeat with item2 running through the list of things carried by Merlin:
		now item2 is noun;
		say "[item1] [item2]";
		now item2 is part of item1;
		now item1 is carried by player.
		

This leads to the run-time error:

[** Programming error: tried to "move" yourself to yourself, which would make a loop: yourself in yourself **]

The telltale text output of item1 and item 2 is:

yourself a tub of margarine

In other words, item1 is ‘yourself’ and item2 is ‘a tub of margarine’. So the problem is with the first item, in the game I gave the beef to Merlin and the Margarine (second). But it only ‘sees’ the second item.

Thank you in advance.

I’m not sure what your “repeat with” is meant to accomplish. The purpose of a “repeat with…running through…” construction is to set item1 to each thing carried by Merlin in sequence…and then you don’t do anything with that value, and set it to something else instead?

1 Like

Matt,
I don’t think you need loops to handle the joining of items here. The following code accomplishes what you want, with the exception that the two joined items aren’t made part of the final item. That should be easy to add.

Padded_Cell_Four is a room.
	The printed name is "Padded Cell Four".
	The description is "The cell is slightly larger on the inside than it looks from the outside. Each of the four walls, the floor and the ceiling are covered with padded fabric. Every inch is covered with notes in varying sizes and styles of text."

Merlin is a man in Padded_Cell_Four.
	The initial appearance is "An old man in a purple robe and purple wizard's cap is standing here."
	The description is "The old man is wearing a purple pointed wizard's cap and matching purple robe, both with stars and meteors on them. Stuck to the robe is a label that says 'Hello, my name is: nilreM.' He is gesturing and gesticulating at you as if casting a spell. But, of course, there's no such thing as magic, not even in your subconscious, so when nothing happens the old man looks confused and turns to read from the wall."
	The carrying capacity is 2.
	Understand "wizard" as Merlin.

Merlin can be powerful or weak.

The block giving rule is not listed in the check giving it to rules.

The beef is a thing carried by the player.
	The printed name is "pound of ground beef".
	The description is "There is nothing special about [the noun]."
	Understand "pound/-- of/-- ground/-- beef" or "pound" as the beef.

The margarine is a thing carried by the player.
	The printed name is "tub of margarine".
	The description is "The relevant description of [the noun] is 'unremarkable.'"
	Understand "tub/-- of/-- margarine" or "tub" as the margarine.

The rubber ball is a thing carried by the player.
	The printed name is "bouncy rubber ball".
	The description is "[We] know as much as I do about [the noun] at this point."
	Understand "bouncy/-- rubber/-- ball" as the rubber ball.

The purple cow is an thing.
	The printed name is "miniature ceramic purple cow".
	The description is "It's a cow. Okay, it's a miniature ceramic purple cow, but 'cow' is still it's most descriptive property."
	Understand "miniature/-- ceramic/-- purple/-- cow" as the purple cow.

Report giving something to Merlin when Merlin is weak:
	say "You hand Merlin [the noun]. He looks it over and tucks it into his belt. He is looking at you expectantly.";
	now Merlin is powerful;
	rule succeeds.

Report giving something to Merlin when Merlin is powerful:
	say "You hand Merlin the [noun].[paragraph break]";
	if Merlin has the beef and Merlin has the margarine:
		say "Merlin grins a wide grin as he studies [the list of things carried by Merlin]. He begins gesturing and gesticulating again but this time his actions appear to have a purpose -- there is a soft glow coming from his hands when he picks up [the list of things carried by Merlin] and they begin to glow as well as his hands. Merlin waves his arms slowly, perhaps as stunned that it is working and the prospect of what the outcome might be. Merlin clears his throat and yells, 'Join!' There is a flash and when the smoke clears, Merlin hands you the item and smiles, more relieved than out of politeness.";
		now the purple cow is carried by player;
		now the beef is nowhere;
		now the margarine is nowhere;
		now Merlin is weak;
	otherwise:
		say "Merlin looks at you confused. He holds out [the list of things carried by Merlin] and shrugs his shoulders.";
	rule succeeds.

Before taking something held by Merlin:
	if the noun is the beef or the noun is the margarine or the noun is the rubber ball:
		say "Merlin hands you [the noun].";
		now the player carries the noun;
		stop the action.

Test magic with "i/give margarine to Merlin/give ball to Merlin/give beef to Merlin/take ball/i/give beef to Merlin/i".

Some notes:
Removing the block giving rule lets you use the existing check rules for the giving it to action. It also means your instead rules have to be report rules.

Setting Merlin’s carrying capacity to 2 prevents the player from giving more than two items to Merlin. The code assumes there are only two joinable items in the game, and they can only be joined into one thing.

2 Likes

Yeah, this is the approach that makes sense to me. Just in case it’s useful though, I suspect the issue with item1 spuriously being the player might have to do with the fact that you were using a pre-existing variable to index your loop - you don’t need to separately initialize those with “…is a number that varies” (it’s like trying to use a global variable as a local variable, if that’s an analogy that makes sense).

1 Like

Thank you for your response, A J Mako – the reason that I was trying to use running with through syntax is that any two objects can be joined in the game. There is one exception (the only ‘right’ combination) but the rest of them are just distractors for the player.

Hopefully that makes sense. I’m now going to try what you have written. Thank you!

Rather than loops, I think it might make sense to use first thing held and next thing held.

merlin is a man in Padded_Cell_Four.  "An old man in a purple robe and purple wizard's cap is standing here."  The description is "The old man is wearing a purple pointed wizard's cap and matching purple robe, both with stars and meteors on them.  He is gesturing and gesticulating at you as if casting a spell.  But, of course, there's no such thing as magic, not even in your subconscious, so when nothing happens the old man looks confused and turns to read from the wall.". the scent of Merlin is "You get the whiff of incense."  Merlin can be powerful or weak.  merlin is weak.

understand "wizard" as merlin.

item1 is a thing that varies.

item2 is a thing that varies.

instead of giving something to merlin when Merlin is weak:
		say "You hand Merlin the [noun].  He looks it over and tucks it into his belt.  He is looking at you expectantly.";
		now merlin has noun;
		now merlin is powerful

instead of giving something to Merlin when Merlin is powerful:
	say "You hand Merlin the [noun].[paragraph break]";
	now merlin carries noun;
	say "Merlin grins a wide grin as he studies [the list of things carried by Merlin].  He begins gesturing and gesticulating again but this time his actions appear to have a purpose -- there is a soft glow coming from his hands when he picks up [the list of things carried by merlin] and they begin to glow as well as his hands.  Merlin waves his arms slowly, perhaps as stunned that it is working and the prospect of what the outcome might be.  Merlin clears his throat and yells, 'Join!'  There is a flash and when the smoke clears, Merlin hands you the item and smiles, more relieved than out of politeness.";
	now item1 is the first thing held by Merlin;
	now item2 is the next thing held after item1; [by Merlin is implied here, because Merlin is the one holding item1]
	say "[item1] [item2]";
	now item2 is part of item1;
	now item1 is carried by player.

This might fail if Merlin is wearing something, however. I’m not sure if first thing held will always consider carried items before worn items.

Thank you, this works. I appreciate that you responded, thank you!