Pushing objects

Hello, all!

There is obviously some feature of pushing that I don’t understand, I have wrestled with this for several hours. What is below is one of several permutations I have tried, it is just the latest iteration.

The basic concept – I am trying to design an object that is pushable between rooms but if pushed through some doorways will get stuck.

cart is a pushable thing [I have tried it as a container, supporter, or thing].

door1 is a door. Door1 is east of kennel and west of kitchen. door1 is open. door1 is unopenable. [I have left out descriptions, etc., where they are not needed].

cartwarn is a number that varies. cartwarn is 0. [this is to give the player a warning before they push through a doorway that is too narrow and get stuck]

check going east with cart:
if player is in kitchen:
if cartwarn is 0:
say, “That looks like a pretty tight fit. Are you sure you want to do that?” instead;
stop the action;
if cartwarn is 1:
now cart is out of play;
now door1 is closed;
say “You try to ram the cart through the eastern doorway, but it now is hopelessly stuck”;
stop the action.
otherwise:
continue the action.

This is the basics, without the room, cart, door descriptions, etc. I have tried this with before, instead of, check, and different ways of phrasing it – before going east in kitchen: (as an example).

The action completes – almost. It will print the messages correctly. And it will close the “door”. But it won’t move the cart to out of play, it still remains in the room.

Any thoughts are appreciated.

door1 is an open unopenable door. Door1 is east of kennel and west of kitchen. 

The cart is a thing in kennel. The cart is pushable between rooms. 

cartwarned is initially false.

instead of pushing cart to east when location is kennel:
	if cartwarned is false:
		now cartwarned is true;
		instead say "That looks like a pretty tight fit. Are you sure you want to do that?";
	now cart is nowhere;
	now door1 is closed;
	say "You try to ram the cart through the eastern doorway, but it now is hopelessly stuck.";
	
Test me with "e / w / push cart e / g / x cart / e".

The reason your code didn’t work has to do with your rule being written for the going action instead of the pushing it to action that triggers it. Pushable objects are implemented by temporarily moving the pushable object to the actor, attempting the Go action, and then moving the object back to the actor’s location. If the Go action succeeds, that will be the new location. If it fails, it will be the original location. Your rule ran during this Go action, moving the cart to nowhere as desired, but then the rest of the pushable object code ran and moved the cart from nowhere back to the player’s location.

Here’s the I6 template code that does this:

[ ConvertToGoingWithPush i oldrm newrm infl;
	i=noun;
	if (IndirectlyContains(noun, actor) == false) { move i to actor; infl = true; }
	move_pushing = i;
	oldrm = LocationOf(noun);
	BeginAction(##Go, second);
	newrm = LocationOf(actor);
	move_pushing = nothing; move i to newrm;
	if (newrm ~= oldrm) {
		if (IndirectlyContains(i, player)) TryAction(0, player, ##Look, 0, 0);
		RulebookSucceeds();
	} else RulebookFails();
	rtrue;
];

Also, please use code tags when posting code. It’s easier for people to help you when they don’t have to reformat your code first.

Thank you for the very detailed explanation.

If anybody were to write an Inform manual, the answers like this should be in it. I can look at examples all day long, but once I understand how something works, I will do much better.

And sorry about the tags, I will do so – I was in my office before class and on a different PC and just wanted to get it posted.