Reset most of the things in the game to their initial conditions.

0 votes
56 views
asked Aug 27 in Authoring by eduardomezencio (36 points)
edited Aug 28 by eduardomezencio

I'm working on a game where it's possible to go back in time. When it happens, things must all reset their position and properties. I created an activiy to reset stuff:

(just to be clear, you can only go back to the starting point, so there's no need to remember the position of things in a given time, just put them back on their initial positions)

Resetting the world is an activity.

For resetting the world:
    now the player is on your bed;
    now the alarm clock is on the chest of drawers;
    now your room's door is closed;
    now ...

The problem is, when the game is finished, this will probably have hundreds and hundreds of lines and will be quite hard to maintain. Is there a better way to do this?

1 Answer

0 votes
answered Aug 28 by HerrRau (26 points)
selected Aug 28 by eduardomezencio
 
Best answer

I don't know of any really concise way of doing this, but I'm no expert. For the rooms that things start in, I'd give every thing a room attribute and when things are reset I'd place them via setting this attribute:

The World is  a room.

Every thing has a room called start position.

The chest of drawers is a supporter.
The bed is an enterable supporter.
The alarm clock is a thing.

The start position of the player is the World.
The start position of the alarm clock is the World.
The start position of the bed is the World.
The start position of the chest of drawers is the World.

When play begins:
    reset the world.

To reset the world:
    repeat with x running through all things:
        now x is in the start position of x.

But this doesn't account for the state of relations, such as being on a supporter, and all the other attributes a thing might have, e.g. open or closed. Also, this way, you couldn't have an item out of play; it would have to get a starting position of "a room called nowhere" or some other dummy room.

commented Aug 28 by eduardomezencio (36 points)
Your answer gave me an idea.. do you think it would work if I did something like this:


Every thing has an object called start position. [object, instead of room here]

A thing can be a-thing-that-start-in-a-room, a-thing-that-start-in-a-container or a-thing-that-start-on-a-supporter.

To reset the world:
        repeat with x running through all things:
                if x is a-thing-that-start-in-a-room:
                        now x is in the start position of x;
                if x is a-thing-that-start-in-a-container:
                        now x is inside the start position of x;
                if x is a-thing-that-start-on-a-supporter:
                        now x is on the start position of x.

or something like that...
commented Aug 28 by HerrRau (26 points)
Maybe you can keep it simpler:  Every thing has an object (you're right there) called start position. And then, in the loop: if the start position of x is a room: now x is in the start position of x; otherwise if the start position x is a supporter: now x is on the start position of x, and so on.
commented Aug 30 by Juhana (246 points)
You can safely use "now x is in the start position of x" regardless of whether the start position is a container, a supporter or something else. Internally there is no difference between in, inside and on; the type of the parent object determines the type of the containment.
commented Aug 30 by eduardomezencio (36 points)
That's great!!! I tried it and it worked, my source is so elegant now! I tried that with a person and it also worked, the item was being carried by the person.

One thing that I tried and didn't work was to assign the player as the initial position of something. It gave the following message: "[...] while this does make sense as an object, it is a value which exists and changes during play, and which doesn't make sense to use when setting up the initial state of things."

What exactly is the player? Is it something like a pointer or a reference would be in c++? Is there a way make this work with the player? I really don't need to right now, but I'm curious...
commented Aug 30 by Juhana (246 points)
"The player" is a global variable that contains a reference to the person object that is the current player character. The default player character is "yourself" so unless you've change it you can write that instead.
commented Aug 30 by eduardomezencio (36 points)
Thank you very much. That's perfect.
commented Aug 30 by eduardomezencio (36 points)
After all that, I actually ended in another problem, but it was worth creating a new question... I asked it here: http://ifanswers.com/1128/copying-location-thing-variable-something-other-than-room
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.
...