Help with a container.

Hi everyone. I’m new to this whole thing so here goes. I’ve been failing at trying to make a TV Remote that can hold batteries but can not hold anything else. And once it has the batteries inside of it, displaying some text. I’ve thus far been able to combine the two and display some stuff but I can’t figure out how to make an “After” or “Instead” action once [batteries] have been put inside of [remote]. I’m sure it’s something silly I’m doing. Thanks for your time!

[code]Combining it with is an action applying to two things.
Understand “combine [something] with [something]” as combining it with.

Living Room is a room. “You stand in the middle of your semi-modern Living Room. The thrift store found furniture lines the walls. You notice a remote on the table.”

Remote is here. It is a container. The description is “A Scamsung television remote. It has no batteries.”

Batteries is here. The description is “Derpacell branded batteries.”

Couch is here. Couch is scenery. The description is “A stained brown couch.”

Television is here. Television is scenery. The description is “A Scamsung branded Television.”
Television can be off or on.
Television is off.
Understand “TV” as Television.

After taking the Remote:
say “You grabbed the remote.”

After taking the Batteries:
say “I bet these will come in handy!”

Instead of combining remote with batteries:
If player carries the remote and the player carries the batteries:
say “You place the batteries in the remote!”;
Remove batteries from play;
Remove remote from play;
now the player is carrying The working remote;
now The working remote is discovered;
stop the action;
otherwise:
say “You should pick them up first.”;
stop the action.

The working remote is a thing.
The working remote can be discovered or undiscovered.[/code]

The way you’ve set things up, it looks like you ought to be able to write your rules about the working remote, since in your code that’s the thing you have once you combine the remote and batteries.

Instead of pushing or switching on the working remote: if the television is off: say "The TV flickers to life!"; now the television is on; otherwise: say "The TV is already on."

Output:

Note that the way you have it written, you have to type “combine remote with batteries” and not the other way around! Also, if you’re going to do this you need to write rules to take care of the cases where the player combines two other things.

On the other hand, it might make sense to use Inform’s built-in container kind to take care of this–then you can just check whether the batteries are in the remote rather than using a new “working remote” thing. That might work like this:

[code]Living Room is a room. “You stand in the middle of your semi-modern Living Room. The thrift store found furniture lines the walls. You notice a remote on the table.”

A remote is here. It is a container. The description is “A Scamsung television remote[if the batteries are not in the remote]. It has no batteries[end if].”

Some batteries are here. The description is “Derpacell branded batteries.”

Couch is here. Couch is scenery. The description is “A stained brown couch.”

Television is here. Television is scenery. The description is “A Scamsung branded Television.”
Television can be off or on.
Television is off.
Understand “TV” as Television.

After taking the Remote:
say “You grabbed the remote.”

After taking the Batteries:
say “I bet these will come in handy!”

Check inserting something into the remote:
if the noun is not the batteries:
say “The only thing that will fit into the remote is batteries.” instead.

Instead of pushing or switching on the remote when the batteries are in the remote:
if the television is off:
say “The TV flickers to life!”;
now the television is on;
otherwise:
say “The TV is already on.”

Instead of pushing or switching on the remote:
say “Pushing buttons on the remote doesn’t seem to accomplish anything. Maybe it needs batteries.”

Check taking the batteries when the batteries are in the remote:
say “There’s no reason to take the batteries from the remote. They’re happy there.” instead.[/code]

Output:

The code you posted compiles and seems to work – what is it not doing that you want it to?

Some general points:

  1. There is a built-in “inserting it into” action which picks up commands such as PUT BATTERIES IN REMOTE. So your new “combining it with” action seems redundant. (If you stick with it you need to allow for COMBINE BATTERIES WITH REMOTE as well as the other way round.)

  2. There’s no real need to have a separate “working remote” object. You can always test whether the batteries are in it or not. You can even define an adjective “working” — the remote is working if the batteries are in it.

  3. If you introduce the remote as "The remote is here, and the batteries with “The batteries are here”, Inform will get that they’re not proper nouns, and that the batteries are plural, and that will help it to get the grammar right.

  4. I would print special messages only the first time the player picks up the batteries/remote. They can get annoying if they’re repeated every time.

Here’s my take on your scenario (with a silly “zapping” action added for demonstration purposes):

Living Room is a room. "You stand in the middle of your semi-modern Living Room. The thrift store found furniture lines the walls. You notice a remote on the table."

The remote is here. It is a container. The description is "A Scamsung television remote. It has no batteries."
The batteries are here. The description is "Derpacell branded batteries."

After taking the remote for the first time:
	say "You grabbed the remote."
After taking the batteries for the first time:
	say "I bet these will come in handy!"
After inserting the batteries into the remote:
	say  "You place the batteries in the remote!";
		
Definition: the remote is working rather than flat if the batteries are in it.
Before printing the name of the working remote: say "working ".

Zapping is an action applying to one thing. Understand "zap [something]" as zapping.
Instead zapping the working remote:
	say "The TV explodes!"
Instead zapping the flat remote:
	say "Nothing happens."	

Don’t forget that assemblies are your friend if you need one object to behave like several.

[rant=code][code]Living Room is a room. “You stand in the middle of your semi-modern Living Room. The thrift store found furniture lines the walls[if remote control is on the coffee table]. You notice a remote control for the TV on the coffee table[end if].”

A coffee table is a supporter in Living Room. It is scenery.

A remote control is a device. It is on the coffee table. The description is “A Scamsung television remote[if battery compartment contains nothing]. It seems rather light as there are no batteries in it[end if]”

a battery compartment is an openable, closed container. It is part of remote control.

Instead of inserting something into remote control, try inserting the noun into battery compartment.

a pair of batteries are on couch. The description is “Some Derpacell branded batteries.”. Understand “battery” as pair of batteries.

Check inserting something into battery compartment:
if the noun is not pair of batteries:
say “That doesn’t belong in the remote. Find some batteries.” instead.

A couch is an enterable supporter. It is in Living room. Couch is scenery. The description is “A stained brown couch.”

A television set is a device in living room. The description is “A Scamsung branded Television[if television set is switched on], currently switched on, but not displaying a clear channel[end if].”
Understand “TV” as the television.

After taking the Remote:
say “You grabbed the remote.”

After taking the Batteries:
say “I bet these will come in handy!”

[You don’t want to use instead in most cases for a complex action. Let the parser do the work]

Check switching on the remote:
if the battery compartment contains nothing:
say “Nothing happens. You probably need to replace the batteries.” instead.

Check switching off the remote:
if the battery compartment contains nothing:
say “Nothing happens. You probably need to replace the batteries.” instead.

Carry out switching on the remote:
try switching on the television set.

Carry out switching off the remote:
try switching off the television set.

Carry out switching on television set:
now television set is lit.

Carry out switching off television set:
now television set is not lit.

After switching on the television set:
say “It lights up, but there is no channel display. Too bad you didn’t pay the cable bill.”

After switching off the television set:
say “The TV goes dark again.”[/code][/rant]

You guys are amazing. Thank you so much for the quick replies, this community is super friendly and welcoming! I’m excited to learn more so I can eventually help others. Thanks again!