Getting a thing from another thing

In my example below, I have a magazine, and when the player tries to take it, a coupon falls out. The idea is that once the coupon appears it appears in his inventory. My code doesn’t quite work (probably the last line). Any suggestions?

A round table is a supporter in Apartment. On the table is a magazine. Instead of taking magazine: say "As you grab the magazine, something slides out from between the pages...a coupon for 1 Free Pit Beef Sandwich at Chaps! You swipe it.". Now the player carries a Chaps Free Pit Beef Sandwich Coupon.

Thanks in advance :smiley:

The last line (the now-phrase) is not inside any rule, and phrases always have to be inside a rule to do their job.
Change the full stop after the output text to a semi-colon, and declare the coupon, and it’ll work as expected.

A Chaps Free Pit Beef Sandwich Coupon is thing. A round table is a supporter in Apartment. On the table is a magazine. Instead of taking magazine: say "As you grab the magazine, something slides out from between the pages...a coupon for 1 Free Pit Beef Sandwich at Chaps! You swipe it."; now the player carries a Chaps Free Pit Beef Sandwich Coupon.
(As it stands Inform takes the last line for an assertion: it creates a person called “Now the player” (!), who carries a thing called “Chaps Free Pit Beef Sandwich Coupon”; they’re both off stage.)

If you use an Instead phrase rather than After, the player won’t ever be able to take the magazine. And since you probably don’t want to make that a magical coupon-relocating machine, you should change the line to After taking the magazine for the first time: so that it never fires more than once.

You’ll need to be careful with rules such as “After taking the magazine for the first time”, because if taking the magazine for the first time ends in failure, this rule will never fire.

Right! So:

After taking magazine when the Chaps Free Pit Beef Sandwich Coupon is off-stage: say "As you grab the magazine, something slides out from between the pages...a coupon for 1 Free Pit Beef Sandwich at Chaps! You swipe it."; now the player carries the Chaps Free Pit Beef Sandwich Coupon.

Wow, I didn’t realize that. That’s a little counterintuitive. Thanks!

Thanks for the help. It’s working for me now. :smiley:

I like this, but it introduces another problem in the future. If we want to give the coupon to a cashier, who puts it in a cash register (potentially off-stage, so that we don’t have to implement a cash register) we could open the magazine again and re-take the sandwich.

I don’t know how complex we want to make this example or if my worries are justified, but here’s what I have. It does seem a bit tangled, but hope it adds something.

[code]the Chaps Free Pit Beef Sandwich Coupon is a thing. The coupon can be unobserved. The coupon is unobserved.

after taking the magazine:
if coupon is unobserved and player has magazine:
say “Oops! A coupon fell out!”;
now the coupon is in room 1;
now the coupon is not unobserved; [yeah, double negative]
the rule succeeds;
continue the action;

test takeit with “take magazine/drop magazine/take magazine”[/code]

Now we can throw the coupon off-stage easily.

You can just use the built-in property “handled” which will be set when the player first has the thing in their inventory.

After taking magazine when the Chaps Free Pit Beef Sandwich Coupon is not handled: say "As you grab the magazine, something slides out from between the pages... a coupon for 1 Free Pit Beef Sandwich at Chaps! You swipe it."; now the player carries the Chaps Free Pit Beef Sandwich Coupon.