Page 1 of 1

Suitcase

Posted: Fri Mar 11, 2005 5:49 pm
by Lysander
Here's what I want ot do.

I want to make a suitcase that contains a handle. Therefore, I want the following actions to result in the following reactions:

-player starts out with handle in inventory, and suitcase in the starting location
-when player holds the handle, he does not in fact hold the suitcase but in fact only holds the handle, whereas the suitcase remains in the current room of the player.
-The player cannot walk away from the suitcase while he holds the handle; wherever he goes while holding the handle, the suitcase will follow
-when the player types "get suitcase," the handle disappears as part of the suitcase and can be examined and whatnot but is not referred to in the inventory list (I.E: "you are carrying a suitcase, attached to which is a handle.")
-make the act of opening the suitcase while the suitcase is not in the player's inventory cause the handle to disappear inside the suitcase again.
-make the suitcase unopenable while the suitcase is in the player's inventory.

What code could I use to make this work?

Posted: Fri Mar 11, 2005 6:04 pm
by Kent
I'm actually just quickly passing through, but until I get a chance to look at or think about this in more depth, one thing I might suggest is to implement this with a handle object based on the 'attachable' class. The attachable class should look after pulling the suitcase object after you, etc. You will have to write some custom code however to handle things like the opening-prevention, hiding the handle upon picking up the suitcase, etc.

Posted: Fri Mar 11, 2005 11:34 pm
by Lysander
That's what I figured, but I couldn't get the attach code to work. I assume I need to do something in routine init or routine main to "activate" the attachable class? Or is there a third library file I need to include? Or possibly a mutant combination!?!

Re: Suitcase

Posted: Sat Mar 12, 2005 10:14 am
by Cryptonomic
This is interesting. Please note that I think I found a few discrepancies in the Hugo Manual about attachables. (Check objlib.h if you want to make sure of things.)
Lysander wrote:Here's what I want ot do.
-player starts out with handle in inventory, and suitcase in the starting location
Okay, so that is simple enough. You can just code the handle object as being in the player object at the start and the suitcase in the starting location.
-when player holds the handle, he does not in fact hold the suitcase but in fact only holds the handle, whereas the suitcase remains in the current room of the player.
Having the handle as a separate object from the suitcase handles this.
-The player cannot walk away from the suitcase while he holds the handle; wherever he goes while holding the handle, the suitcase will follow
You could use attachables, it seems. Here is another example (without using attachables):

Code: Select all

class newLocation
{
  inherits room
  after
  {
    location DoGo
    {
      if (handle in player and suitcase in old_location)
      {
        move suitcase to location
      }
    }
  }
}
So here I have set things up such that if the player moves from any room that is of type newLocation, then a check will be made: (1) do they have the handle in their possession and (2) is the suitcase in the location they moved from.

If so, move the suitecase to the new location that they moved to.

That is just one possible way. (I think. I tried this out and it seems to work for at least up to this level of what you want to do.) Let me try working with the other specifics that you gave.

Re: Suitcase

Posted: Sat Mar 12, 2005 10:31 am
by Cryptonomic
Lysander wrote:-when the player types "get suitcase," the handle disappears as part of the suitcase and can be examined and whatnot but is not referred to in the inventory list (I.E: "you are carrying a suitcase, attached to which is a handle.")
Okay, so for this, how about something like this:

Code: Select all

object suitcase "suitcase"
{
  in emptyroom
  noun "suitcase"
  long_desc { "A basic suitcase." }
  inv_desc { "a suitcase" }

  before
  {
    object DoGet
    {
      move handle to suitcase
      return false
    }
  }

  after
  {
    object DoDrop
    {
      move handle to player
      return false
    }
  }
}
The inv_desc property can make sure that the handle does not get listed as part of the suitcase. The after routine then just makes sure that we return the situation to normal. By the way, I am returning false to make sure that Hugo knows that whatever it would normally do still needs to be carried out.

I think the before/after properties could help you with the other elements on your list as well. In other words, you can dictate how the suitcase will respond to being opened, for example, or when it is allowed to be opened.

I am not sure if this is all the "best" way to do this (probably not) but does it help? A little? Sorta?

Posted: Mon Mar 21, 2005 3:59 pm
by Lysander
Yes. Much. Thank you. I'll add this in... er... whenever I get a chance, which probably won't be for a little while, and see what else needs doing. Basically i'm trying to make everything act as "real-y" as possible for hte purposes of learning the various ins and outs of the language.