[I7] Random chosen thing from carry out used in report text

I’m trying to create a new action for pickpocketing. Here’s my code so far (currently all I’m trying to get it to do is pick a random pickpocketable item from the target and dump it in the room):

[code]Pickpocketing is an action applying to one visible thing. Understand “pickpocket [thing]” as pickpocketing.

Check pickpocketing:
if the noun is not a person:
say “Good idea! That was sarcasm.” instead;
if the noun is the player:
say “You successfully steal from yourself. You are now carrying the entire inventory of yourself.” instead;
if the noun is aware:
say “You’re about to delve into [the noun]'s pockets, but realize it would be far too risky.” instead;
if the noun is a person who is not carrying a pickpocketable thing:
say “You rummage in [the noun]'s pockets, but find nothing you can take.” instead.

Carry out pickpocketing:
now a random pickpocketable thing (called the item) that is carried by the noun is in the location of the player;
say “You successfully pickpocket [an item] from [the noun].”

[Report pickpocketing:
say “You successfully pickpocket [the item] from [the noun].”][/code]

You may notice that my report block is commented out. That’s because, when I tried to reference [the item], it didn’t recognize “item”. When I moved that line to the carry out, where I assign “item”, it compiles and runs fine, but the only problem is that instead of printing the item that’s pickpocketed, it prints “nothing”. The code works as expected otherwise, so I’m fairly certain I’m selecting a random item from the noun’s inventory properly.

So how do I get my report (or the carry out, if necessary) to reference the proper item in text?

Refer to “the noun” rather than “the item”.

By the way, your action should apply to one thing, not one visible thing. The visible adjective removes the requirement that the player be able to touch the noun, which in this case you’d want. If you want to forbid pickpocketing in the dark, make it an action “requiring light”.

“The noun” refers to the person being pickpocketed. For example, if the parser reads “pickpocket guard”, [the noun] in text becomes “the guard”.

And thanks for the other tip, I removed “visible”.

You could do it in one rule like this:

Carry out pickpocketing: let the item be a random pickpocketable thing that is carried by the noun; now the item is in the location of the player; say "You successfully pickpocket [an item] from [the noun]."

(And if you want to transfer the item to the player’s inventory you could say “now the player carries the item”.)

If you want to have different rules referring to the same item – so the item gets set in a carry out rule and talked about in a report rule – then you could try using action variables, as in section 12.10 of Writing with Inform. But that might be more than you need right now.

Ah, I had no idea “let” was a thing. Sometimes I crawl through the documentation for hours and miss the most obvious stuff.

Thanks for your help, that worked perfectly. I might look into using action variables (another obvious thing I missed, even after looking through the Advanced Actions tab) since I like easily expandable code.

If you want to keep the reporting in a Report rule, I think action variables would be the way to go.

The pickpocketing action has a thing called the stolen item.

Carry out pickpocketing begin;
now the stolen item is a random pickpocketable thing that is carried by the noun;
now the stolen item is in the location of the player; [This throws it on the ground rather than having the player keep it; is that intentional?]
end.

Report pickpocketing begin;
say "You successfully pickpocket [a stolen item] from [the noun].";
end.

I haven’t tested this but it should be pretty close.

That’s essentially what I wrote. And it was intentional to just put it on the ground, I’ve since changed it to putting it in the player’s inventory though.