Dragging with and without directions

I’m having a variety of problems here, and this one really has me stumped.

Here’s the deal. You’re stuck in a basement and the only way you can get out is to drag a chair under the window and then stand on it to get out the window. The window is on the east side of the room.

I’d like to respond to all the things the player might say:

Shove chair
Shove chair to window
Shove chair east

And the same with push, pull, and drag.

Here’s what I have:

[code]Shoving is an action applying to one thing.
Understand “shove [something]” as shoving.
Understand “push [something]” as shoving.
Understand “pull [something]” as shoving.

Check shoving:
If the noun is fixed in place, say “It won’t budge.” instead.

Carry out shoving:
say “You shove the [noun] around the room aimlessly.”

Shoving it to is an action applying to two things.
Understand “shove [something] to [something]” as shoving it to.
Understand “push [something] to [something]” as shoving it to.
Understand “pull [something] to [something]” as shoving it to.
Understand “shove [something] to [direction]” as shoving it to.
Understand “push [something] to [direction]” as shoving it to.
Understand “pull [something] to [direction]” as shoving it to.
Understand “shove [something] [direction]” as shoving it to.
Understand “push [something] [direction]” as shoving it to.
Understand “pull [something] [direction]” as shoving it to.

Check shoving it to:
If the noun is fixed in place, say “It won’t budge.” instead.

Check shoving:
If the noun is not the chair, say “Ok.” instead.

Carry out shoving it to:
If the second noun is the window
Begin;
say “You shove the chair under the window.”;
now the chair is climbable;
Otherwise;
say “Ok.”;
End if.

Carry out shoving it to:
If the direction is east
Begin;
say “You shove the chair under the window”;
now the chair is climbable;
Otherwise;
say “You shove the chair away from the window”;
now the chair is useless;
end if.[/code]

Shoving without a second noun or direction works, as does pulling, pushing and dragging without a second noun or direction.

Shoving with a second noun was working until it mysteriously stopped.

Shoving with a direction gives me the mysterious message “You must name something more substantial.”

I realize that even if it were working, “Shove chair east” generally means shoving it out of the window and into the next room. I don’t want it to do that, but I’d like to allow that command from the user if possible. Nothing in the game will be pushable between rooms so I don’t care if I preserve the built-in functionality.

I don’t believe I need a mini-map inside of the room, as it seems like I can just assume that pushing the chair east will always position it under the window and pushing it anywhere else will move it away.

Additionally, I got these weird results that give two lines each:

[code]>shove chair to window

You shove the chair under the window.

You shove the chair under the window

shove chair to table

Ok.

You shove the chair under the window[/code]

Looks like the two “carry out shoving” blocks are both firing, which makes sense I guess, but I’m not sure how to code this otherwise. Also, why is it assuming that the direction is east in the second block?

Since I’m having a variety of problems, I’m not sure where to start:

Can I make “shove chair east” do something special rather than try to push it into the next room?
How do I handle not having two “carry out” phrases for “shoving it to” when I have both a second-noun variety and a direction variety to implement?
How do I implement “If the direction is east”?
What’s wrong with my shoving-with-a-second-noun code, that it always thinks I’m heading to the window?
What the heck does “You must name something more substantial” mean?

Sorry this is so convoluted. Any advice is appreciated!

First, I suggest you use the existing “pushing” action:

[code]Understand the command “shove” as “push”.

Instead of pushing the chair:
say “You shove the [noun] around the room aimlessly.”

Instead of pulling the chair:
try pushing the chair.
[/code]

Then the shoving it to [something] code. This is adapted from the Inform recipe book chapter 3.2. example 197:

[code]Internal position is a kind of value. The internal positions are nowhere at all, over by the window and over by the west side.

The chair is in the basement. The current chair position is an internal position that varies. The current chair position is over by the west side.

Understand “push [something] to [something]” as pushing it over to.
Understand “pull [something] to [something]” as pushing it over to.
Pushing it over to is an action applying to two things.
The pushing it over to action has an internal position called the old position.
The pushing it over to action has an internal position called the new position.
Setting action variables for pushing something over to something:
now the old position is the current chair position;
now the new position is nowhere at all;
if the second noun is the window, now the new position is over by the window.

Check pushing it over to:
if the noun is not the chair, say “That’s not something you can push.” instead;
if the player is on the noun, say “Not while you are standing on [the noun].” instead;
if the new position is nowhere at all, say “It wouldn’t do any good to push the chair there.” instead;
if the new position is the old position, say “The [noun] is already [new position].” instead.

Carry out pushing it over to:
change the current chair position to the new position.

Report pushing it over to:
say “You shove [the noun] [new position].”[/code]

Then handling PUSH CHAIR EAST:

Instead of pushing the chair to: if the second noun is east: try pushing the chair over to the window; otherwise: say "It wouldn't do any good to push the chair there."

That should do it.

The direction, when given as a player command, is a noun or a second noun, in this case “if the second noun is east…”

While “if the direction is east” makes sense to a human reader, remember that (with some exceptions) the compiler disregards all instances of “the” and “a”. So it reads that as “if direction is east”, or in other words, “if east is a direction”. Which is always true.

The game expects a physical object, not a direction. You can’t “push east” any more than you can eat west or sit on south.

I was thinking I couldn’t do this, since I was going to do new things with it. But you’re right, it appears I can use the existing stuff.

So this will work even if the player says “Push chair east” instead of “Push chair to east”? I wouldn’t have guessed that.

I wouldn’t have guessed that either, especially since I saw some code using “blah [direction]” in the documentation. That’s easy!

Thanks so much Nitku!

Just for clarification, is the “nowhere at all” designed to simplify where the chair can move and how to keep track of it?

I consider using only “over by the window” and “away from the window”, with East leading to “over by the window” (perhaps telling the player if the chair is already there) and all other commands (move chair to table, move chair west, move chair South, etc) leading to “away from the window”. I think it might be a bit awkward to be allowed to move the chair east, but then be stopped from moving it elsewhere, unless that’s a nightmare to implement.

Guess I’ll go tinker with that right now and see what happens.

For some reason I can still push the chair while I’m on it – sometimes. Code:

Understand the command "shove" as "push".
Understand the command "scoot" as "push".

Instead of pushing the chair:
   say "You shove the [noun] around the room aimlessly."

Instead of pulling the chair:
   try pushing the chair.

Internal position is a kind of value. The internal positions are over by the window and toward the west side of the room.

The current chair position is an internal position that varies. The current chair position is toward the west side of the room.

Pushing it over to is an action applying to two things.
Understand "push [something] to [something]" as pushing it over to. 
Understand "pull [something] to [something]" as pushing it over to.
Understand "push [something] [something]" as pushing it over to. 
Understand "pull [something] [something]" as pushing it over to.
Understand "push [something] under [something]" as pushing it over to. 
Understand "pull [something] under [something]" as pushing it over to.
Understand "push [something] over by [something]" as pushing it over to. 
Understand "pull [something] over by [something]" as pushing it over to.

The pushing it over to action has an internal position called the old position. 
The pushing it over to action has an internal position called the new position. 

Setting action variables for pushing something over to something: 
    now the old position is the current chair position; 
    if the second noun is the window
    Begin;
      now the new position is over by the window;
    Otherwise; 
      now the new position is toward the west side of the room;
    End if.

Check pushing it over to: 
    if the noun is fixed in place, say "It won't budge." instead; 
    if the noun is not the chair, say "That hardly seems helpful." instead; 
[b]    if the player is on the noun, say "You'll have to get off the [noun] first." instead;[/b]
    if the new position is the old position
    Begin;
      If the new position is over by the window,
        say "The [noun] is already [new position]." instead;
   End if.

Carry out pushing it over to: 
   change the current chair position to the new position.

Instead of pushing the chair to:
   if the second noun is east
   Begin;
      If the current chair position is over by the window
      Begin;
        say "The chair is already over by the window." instead;
      Otherwise;
        say "You shove the chair under the window.";
        change the current chair position to over by the window;
      End if; 
   End if;
   if the second noun is west 
   Begin;
     change the current chair position to toward the west side of the room;
     say "You shove the chair west."; 
   End if;
   if the second noun is south 
   Begin;
     change the current chair position to toward the west side of the room;
     say "You shove the chair south."; 
   End if;
   if the second noun is north 
   Begin;
     change the current chair position to toward the west side of the room;
     say "You shove the chair north."; 
   End if.

Report pushing it over to: 
     say "You shove [the noun] to [the second noun]."

Play:

What the heck? Any advice?

You aren’t checking whether the player is on the chair when they push the chair to directions. Try to replace your “instead of pushing the chair to” rule with this:

Instead of pushing the chair to: if the second noun is east Begin; try pushing the chair over to the window; otherwise; silently try pushing the chair over to the table; if the rule succeeded, say "You shove the chair [second noun]."; End if.

Now pushing in directions goes through same checking mechanisms as pushing over to objects. This also fixes a bug that caused empty lines with intermediate directions (PUSH CHAIR NORTHWEST), but note that PUSH CHAIR UP and PUSH CHAIR DOWN still give nonsensical answers. (You might also want to check cases like PUSH CHAIR TO CHAIR and PUSH CHAIR TO ME.)

Thanks for that, Nitku. That worked.

What stumped me is that if I open a brand new project and test pushing:

[code]the onlyroom is a room. The otherroom is north of the onlyroom.

The box is a supporter in the onlyroom. The box is enterable. The box is pushable between rooms.[/code]

The not-pushing while on the item is built-in:

So I’m confused. It looked to me like the “pushing it over to” check should have affected both “push chair east” and “push chair to table”.

Why didn’t that check code work for “east”, and how did I override the built-in check that works in the test game?

Sorry for beating this dead horse. I like to understand rather than just copy.

Thanks for the help!

It seems like every time I fix something I break something else. Now I can’t get out the window after moving the chair, which was the whole point. This may be unrelated to the push code, not sure. I’ll try to copy all the relevant bits of code.


[map boundary code]
Instead of going west when the player is in the churchyard and the window is intact: say
  "The church door is locked so you can't get inside." [I don't want the player to think about the basement window until she notices it]
Instead of going west when the player is in the churchyard and the window is broken:
  If the player is carrying something, say "It looks like a big drop. Better put your stuff down first." instead;
  If the purple egg is found, say "There's nothing more to see in there, and your feet still hurt from last time." instead;
  If the purple egg is unfound
  begin;
    If the current chair position is over by the window
    Begin;
      say "You carefully climb through the window, landing on the chair below.";
      now the player is in the Church Basement;
      now the player is on the chair;
    Otherwise;
       say   "You carefully climb into the window and scoot yourself through. There is a big drop as you hit the basement floor. Luckily it is carpeted, but you still hurt your knees.";
      now the player is in the Church Basement;
    End if;
  End if.

Instead of going east when the player is in the church basement:
  If the player is not on the chair,
  say "The window is too high. You can't get back up there." instead;
  If the player is on the chair and the current chair position is over by the window
  Begin;
   say "You climb out the window with some difficulty.";
   now the player is in the Churchyard;
  End if;
  If the player is on the chair and the current chair position is toward the west side of the room,
   say "The window is too high. You can't get back up there." instead.

Instead of entering the window when the player is in the Church Basement:
 Try going east instead.

Instead of entering the window when the player is in the churchyard and the window is intact:
  Say "The window is closed."

Instead of entering the window when the player is in the churchyard and the window is broken:
  try going west instead.

Instead of going up when the player is in the Church Basement:
  Try going east instead.

Instead of going down when the player is in the churchyard and the window is intact:
  say "You can't go that way." instead.

Instead of going down when the player is in the churchyard and the window is broken:
  try going west instead.

[push-related code]

Instead of pushing the chair:
   say "You shove the [noun] around the room aimlessly."

Instead of pulling the chair:
   try pushing the chair.

Internal position is a kind of value. The internal positions are over by the window and toward the west side of the room.

The current chair position is an internal position that varies. The current chair position is toward the west side of the room.

Pushing it over to is an action applying to two things.
Understand "push [something] to [something]" as pushing it over to. 
Understand "pull [something] to [something]" as pushing it over to.
Understand "push [something] [something]" as pushing it over to. 
Understand "pull [something] [something]" as pushing it over to.
Understand "push [something] under [something]" as pushing it over to. 
Understand "pull [something] under [something]" as pushing it over to.
Understand "push [something] over by [something]" as pushing it over to. 
Understand "pull [something] over by [something]" as pushing it over to.

The pushing it over to action has an internal position called the old position. 
The pushing it over to action has an internal position called the new position. 

Setting action variables for pushing something over to something: 
    now the old position is the current chair position; 
    if the second noun is the window
    Begin;
      now the new position is over by the window;
    Otherwise; 
      now the new position is toward the west side of the room;
    End if.

Check pushing it over to: 
    if the noun is fixed in place, say "It won't budge." instead; 
    if the noun is not the chair, say "That hardly seems helpful." instead; 
    if the player is on the noun, say "You'll have to get off the [noun] first." instead;
    if the new position is the old position
    Begin;
      If the new position is over by the window,
        say "The [noun] is already [new position]." instead;
   End if.

Carry out pushing it over to: 
   change the current chair position to the new position.

Instead of pushing the chair to:
   if the second noun is east
   Begin;
      try pushing the chair over to the window;
   otherwise; 
      silently try pushing the chair over to the table;
      if the rule succeeded, say "You shove the chair [second noun].";
   End if.

Report pushing it over to: 
     say "You shove [the noun] to [the second noun]."

Instead of climbing the chair:
  try entering the chair.

Instead of climbing the window:
  try entering the window.

Problem:

Sorry I’m so high-maintenance.

EDIT: It occurs to me that the response suggests that the “current chair position” isn’t getting set to “over by the window”.

I tried this but it didn’t help:

Instead of pushing the chair to: if the second noun is east Begin; try pushing the chair over to the window; if the rule succeeded, now the current chair position is over by the window; otherwise; silently try pushing the chair over to the table; if the rule succeeded, say "You shove the chair [second noun]."; End if.

Maybe it was redundant anyway… I’m confused.

Instead rules override check rules. They literally mean “instead of doing this action, don’t even try doing it but do this instead and nothing else”. (They could not function at all if they went through the normal check rules: you couldn’t, for example, do ‘Instead of pushing the chair to north: say “It’s too heavy.”’ because the response would always be “The chair cannot be moved from place to place”, as the standard library check rule would intervene.)

If you do an after rule (After pushing the chair to east: …) you would go through the normal check rules. (But an after rule would not work here, because you specifically want to override the check rules. An after rule means “After this action has succeeded under normal conditions, do this.”)

The getting-out-of-window problem is this:

Instead of going east when the player is in the church basement:

Perhaps confusingly the player is not in the church basement when she is on the chair. A thing can be “in” only one thing at a time. So the player is in the chair, and chair is in the basement. When you need to know the room where the player is, use “location”. So just change that line to

Instead of going east when the location is the church basement:

It is being set. The instead rule makes the game act exactly as if the player had typed PUSH CHAIR TO WINDOW; the “try doing” goes through the check rules, carry out rules and report rules as normal. “Silently try doing” does the same, except that it skips the report rules.

There’s nothing to apologize. That’s a very good learning strategy.

Instead of going east when the location is the church basement:

Perfect! That was a confusing one. Thanks Nitku!