Attaching things in any order

Hi! I’m working on a puzzle where the player has to go through the (simplified) process of jumping a car. They have jumper cables, a car engine and a power source. Once the cables are attached to the power source and the car engine, the car-start state is true, the player can travel, and the game continues.

I’d like for it to not matter whether the cables are attached to the engine first or the power source first. I’d like the cables to be the only thing that can be attached to another object, and I’d like the only objects the cables can be attached to to be the power source and the engine.

Seems simple. I know it is simple and I’m missing something. I looked at example 427, “What Makes You Tick,” and it’s pretty much what I’m trying to do. But that example is about making a new object you can carry aroudn, not putting stationary objects in a state of hooked-uppedness. I also found this, which is really cool, but it might be overkill for what I’m doing here, and I’m not sure how to apply it.

I feel kind of deflated not being able to abstract “What Makes You Tick” into what I want, but we live in the world we live in, and we work with the brains we have. Any help is appreciated.

1 Like

I can think of a few ways to do it. The simplest, which doesn’t really try to physically simulate the cables being clipped to different things, would be to create flags, one something like “battery-attached” and one “engine-attached”. Then, instead of putting the cables on the battery, you could make the cables be “battery-attached”. When turning on the engine, if the cables are both battery-attached and engine-attached, it would work. The disadvantage to doing it this way is that you’d have to also hand code various other things, like what happens if the player attaches the battery, and then leaves the room carrying the cables (presumably undoing all the attachments). You would probably also need to vary the description of the cables so the player can always tell what’s attached and what’s not.

A more complex way to do this would be to make a new relationship defining what it means for one thing to be attached to another. (Take a look at chapter 13.7 of Writing with Inform, which talks about a making a rope that can be tied to various things – there’s a lot of rope code you won’t need in there, but the part about tying and untying should be helpful.) To me this seems more worth it if you want the cables to be clippable to anything, but it still might be useful to make one really robust interaction with the cables, engine, and battery.

1 Like

You might be able to adapt the method of Example 427 just by removing the word “carried” from the definition of “combining it with”. But this looks more complicated than you need to be.

Here is my (not very polished) attempt at realizing Caleb’s first suggestion. It’s an ad hoc method, but not too complicated, and I don’t think any other method is going to require any less attention to details.

Garage is a room. "The [power source] is here."  

The power source is a scenery thing in Garage. 
The car is a vehicle in Garage. The car can be powered or unpowered. 

The player carries some jump leads.  
The jump leads can be attached to the power source. The jump leads can be attached to the car.
After printing the name of the jump leads when listing contents: 
	if the jump leads are attached to the power source and the jump leads are attached to the car:
		say " (connecting the car to the power source)";
	else if the jump leads are attached to the power source:
		say " (plugged into the power source)";
	else if the jump leads are attached to the car:
		say " (plugged into the car)".

Before going when the player carries the jump leads and the jump leads are attached to the power source or the jump leads are attached to the car:
	say "(dropping the jump leads)";
	silently try dropping the jump leads.

The block tying rule does nothing when tying the jump leads to the car or tying the jump leads to the power source.

Check tying the jump leads to the power source when the jump leads are attached to the power source:
	say "They are already attached." instead.
Check tying the jump leads to the car when the jump leads are attached to the car:
	say "They are already attached." instead.

Carry out tying the jump leads to the power source:
	now the jump leads are attached to the power source.
Carry out tying the jump leads to the car:
	now the jump leads are attached to the car.
	
Report tying the jump leads to something:
	say "You attach the leads."

After tying the jump leads to something when the jump leads are attached to the power source and the jump leads are attached to the car:
	now the car is powered;
	if the car was unpowered: 
		say "As you attach the leads, the car engine bursts into life.";
	else:
		say "You fasten the leads. The engine was already powered."

Understand "detach [something]" as taking. 
Understand "detach [jump leads] from [something]" as removing it from.

Detaching it from is an action applying to two things.
Understand "detach [jump leads] from [car]" as detaching it from when the jump leads are attached to the car.
Understand "detach [jump leads] from [power source]" as detaching it from when the jump leads are attached to the power source.
Understand "detach [jump leads]" as detaching it from when the jump leads are attached to the power source or the jump leads are attached to the car.

Rule for supplying a missing second noun when detaching the jump leads from:
	if the jump leads are not attached to the car:
		now the second noun is the power source;
	else:
		now the second noun is the car;
		if the jump leads are attached to the power source:
			say "(from the car)".

Carry out detaching the jump leads from the power source:
	now the jump leads are not attached to the power source.
Carry out detaching the jump leads from the car:
	now the jump leads are not attached to the car.

Report detaching the jump leads from:
	say "You detach the leads."

Comments: I used the built in “tying it to” action just because the command “ATTACH” is associated to this action by default.

The “detaching” action is new, and needs attention (because the player might try detaching things elsewhere in the game, and should be rewarded with sensible responses). I have directed it to the “taking” or “removing it from” actions using grammar tokens, but possibly this would be better done using instead rules.

My “attached to the power source” and “attached to the car” flags correspond to Caleb’s “battery-attached” and “engine-attached”.

My solution to the leaving-with-the-attached-jump-leads issue that Caleb mentioned was just to have the player automatically drop them first.

2 Likes

Hi! I didn’t forget about this - it’s just been a heck of a week at work. I tried your code, jrb, and after some minor changes, it does exactly what I want it to do. Thanks for your help!

2 Likes