Moving something to the previous location

Hey all-
I have an object that the player can possess (by loving it), and then if the player performs the correct action on the object (hating it), they can be transported back to their previous location (the room they were in when they loved the object).
I’ve done this by creating a new location- The Object’s Perspective, and moving the player there when they love the object, then moving them back when they hate the object.

But there are big problems with this approach:
1.) In order to hate the object (and end the possession), I have to move the object itself to Object’s Perspective so that it is available to be hated in order to move the player back to the previous location, then move the object back to the previous location as well so everything is as it was.

2.) But the object can be moved from room to room, so I don’t know where it will be when the player loves it. Since I have to move the object as well as the player into Object’s Perspective, I don’t have any known anchor in the previous location, so I can’t say “move player to object’s location” or anything like that.

I’d like to change the way I’m doing this to something more like this (which doesn’t work, of course, but hopefully I’m just not using the right syntax):

Before going somewhere (this is the mobility rule):
	If the player is immobile:
		Say “You are stuck and cannot move!”;
		stop the action.
		After loving something, now the player is immobile.
		After hating something, now the player is mobile.

Currentlocation is a text that varies.

Each turn, let currentlocation be location's description.

Carry out loving the key: 
	say "The room looks different. You are seeing it from the perspective of the key.";
	now the player is immobile; 
	now the description of the location is "You are inside of the key. You'll have to find a way out.".

Carry out hating the key:
	if we have loved the key:
		say "With a vacuum sensation, you return to the room.";
		now player is mobile;
		now the description of the location is currentdescription;
	otherwise:
		say  "You feel a strange vacuum like sensation, but nothing else happens."

Can someone help me get something like this to work? Or propose a way I’m not thinking of to identify the player’s last location, wherever that may be, and move them to it?

I’m not sure I have my brain fully wrapped around how this works – the location-description swapping is sort of confusing to me – but seems like you could just do this with a global variable that gets set every time you love an object? Sort of like this:

Loved-from-place is an object that varies.

Carry out loving:
    Now loved-from-place is the location;
    (Your actual code goes here, which I guess includes moving the player and the loved object?);

Carry out hating:
    Now the player is in the loved-from-place;
    Now the noun is in the loved-from place;

Does that seem like it might work?

(There might be other ways to make this work a little more simply, like putting the loved object in-scope rather than moving it around, but that might complicate other pieces of your code so that might not be worth it at this point).

EDIT: initial post had “location that varies” rather than “room that varies”, since I’m a dummy.

EDIT NUMBER 2: actually should be “object that varies”, this is not my morning!

Hmm. I’m not sure I understand how this works, but here’s some code I think might work with this?

Loved-from-place is a location that varies.

Carry out loving the key:
		Now loved-from-place is the location;
		Now player is immobile;
		Instead of printing the location's description, say "You're in the key";
	
Carry out hating the key:
	if we have loved the key:
		Now the player is in the loved-from-place;
		now player is mobile.
	otherwise:
		say  "You feel a strange vacuum like sensation, but nothing else happens."

But this throws this error message:

Problem. The sentence ‘Loved-from-place is a location that varies’ appears to say two things are the same - I am reading ‘Loved-from-place’ and ‘location that varies’ as two different things, and therefore it makes no sense to say that one is the other: it would be like saying that ‘Choucas is Hibou’. It would be all right if the second thing were the name of a kind, perhaps with properties: for instance ‘The Hall is a lighted room’ says that something called The Hall exists and that it is a ‘room’, which is a kind I know about, combined with a property called ‘lighted’ which I also know about.

You want “object that varies”.

(“Room” might make more sense, but the location global variable is defined as an object.)

Oops, sorry! Meant to type “room”, not “location” – perils of writing off the cuff.

Huh, really? That’s helpful to know – I feel like I’ve used “room that varies” before and must have caused some bugs!

It doesn’t cause bugs. While location is defined as an object, it should always be a room or nothing unless you mess around with the standard rules. (And nothing causes bugs on its own, I believe.)

1 Like

This worked great.
And I’m a big fan of your games, Andrew. Fangirling!

The reason you can’t make the variable a room if you’re using nothing is because unlike in a lot of languages, nothing is not considered a room, or any other type of object more specific than object. Sometimes you see examples where they create a room disconnected from everywhere else that can be used like nothing for rooms.

This would probably do far too much violence to your code at this point, but making a fake container of the object could be a relatively easy way to do this:

A possessible is a kind of container. A possessible is always enterable. A possessible is always closed. A possessible is never openable. A possessible is always trans\
parent.

Rule for printing the name of a possessible (called possessed):
  say “[printed name of possessed]”;
  omit contents in listing.

The examine containers rule does nothing when examining a possessible.

Carry out loving a possessible:
  move the noun to the location; [just in case the player had been carrying it]
  Move the player to the noun;
  Now the player is immobile;

Carry out hating a possessible when the noun contains the player:
    Move the player to the location of the noun;
    Now the player is mobile.

Instead of examining a possessible when the noun contains the player:
    say "You can't see it from its own perspective."

It remains in scope; looking still gets you the description of the room with the object omitted 'cause you’re in it; there’s no description-rewriting to do. Of course, this technique wouldn’t work if you wanted an actual usable container to be possessible.