Copying the location of a thing to a variable when it's in something other than a room.

0 votes
38 views
asked Aug 30 in Authoring by eduardomezencio (36 points)

I'm using this to get the place where each object start the game and save to a variable:

A thing have an object called initial position.

When play begins:
    repeat with x running through all things:
        now the initial position of x is the location of x.

Now, take a look at what this does then the thing is in a container, on a supporter, etc...

>showme ball
...
location: in the box in Room 101
...
initial position: Room 101

it only copies only the room, not the entire location. Is there a way to make this work?

1 Answer

+1 vote
answered Aug 30 by bg (692 points)
selected Aug 30 by eduardomezencio
 
Best answer

You could use "holder" instead of "location":

now the initial position of x is the holder of x.

See ยง8.17. Looking at containment by hand.

But it will only include the object that is directly holding x, whether that is a container, supporter, or room. It'll be "box," for instance, not "the box in Room 101."

If you want to print the text of the holder and the location, and don't need the variable to be an object, you could do something like this:

When play begins:
    repeat with x running through all things:
        if the holder of x is a room:
            now the start position of x is "[the location of x]";
        otherwise:
            now the start position of x is "[the holder of x] in [the location of x]".
commented Aug 30 by eduardomezencio (36 points)
Thank you, this solved the problem for good.

I needed it to be an object to use it later to reset the positions of all things in the game, like I described in this question: http://ifanswers.com/1113/reset-most-of-the-things-in-the-game-their-initial-conditions but there is no need to store the location of the holder, because the holder is alreay keeping his own location stored.
This site is now closed.
As of 1st November 2015, this site is a read-only archive. For more information see the intfiction forum post

Welcome to IF Answers, a site for questions and answers about Interactive Fiction.

Technical questions about interactive fiction development tools such as Inform, Twine, Quest, QuestKit, Squiffy, Adrift, TADS etc. are all on-topic here.

Non-technical questions about interactive fiction are also on-topic. These questions could be about general IF design, specific games, entering the IF Comp etc.
...