[SOLVED]Make exits command dosent work

Im trying to make this thing where the player is in a box and can use a penknife to make a hole in said box, but I cant figure out how to get the penknife to create an exit when used on the box. Please help.


Io

It's easier to have a NAMED exit already be in existence, invisible, and using the penknife on the box makes it visible.


cool,thanks


There are some cases where it would be useful to create an exit or an object, but not many. In most cases, there's a few better ways to handle the situation where you want to create something.

  1. Lock it

In cases like your example, locking the exit might make more sense than creating it. That way, when the player types "go out" before cutting their way out of the box, they can see a lock message like "The box isn't open"; or even set the exit's locked message to "You can't go that way".

It's not quite what you asked for, but depending on the setup it might feel more natural to the player if they have an exit they can't go through. I'd save invisible exits for situations where it's not clear you can go that way. A person inside a box is likely to be trying to find a way out, so it's natural that the player may try "go out", and it's a nice touch to give them a meaningful message.

  1. Make it invisible

As io points out, you can make your object or exit invisible initially, and then make it visible when you need it. For most cases, an invisible object is pretty much the same as it not existing.

  1. Make it somewhere else

If you don't know where the object or exit will be needed (for example if there are multiple compartments in a box, and the player can move to any of them before cutting their way out), rather than an invisible exit it's easier to put one somewhere else entirely; maybe outside player space, in a room the player can't reach yet, or inside an object that isn't a container. Then when you need it, you can just do MoveObjectHere (name_of_exit) or name_of_exit.parent = game.pov.parent.

(Most object functions also work on exits; such as moving them around the map. All exits are effectively teleporters, so moving them to a different room without changing the destination will work fine)

  1. Clone an existing one

Probably not so useful for exits, but it could be useful. Functions such as CloneObject work perfectly well on exits if you need to. And if you want to create multiple copies of the same object, having an "original" object that you can clone means that you can still use the GUI to modify its attributes easily. This is usually easier and more efficient (both for the programmer and the Quest engine) than creating a new object and setting all its attributes.

  1. Actually create a new one

There's very few circumstances where you'd need to do this, but there are a few. Most notably if you've got a script that creates a random dungeon, or if the player has a stick of dynamite that allows them to make a hole through any wall in a dungeon.

You probably wouldn't end up doing this, but in case you do:

Create objects with create (name)

For example:

create ("jellyfish")
jellyfish.alias = "John the Jellyfish"
MoveObject (jellyfish, aquarium)

or if you might want to create multiple objects of the same type, you need to give them different names. For example:

// We get a unique name, which might end up being "fish", or "fish3", of "fish1337"
fishname = GetUniqueElementName ("fish")
create (fishname)
// then create a variable pointing to the newly-created object so we can do stuff with it
new_fish = GetObject (fishname)
if (new_fish = null) {
  error ("Couldn't create fish - maybe we're out of memory?")
}
else {
  new_fish.alias = "Yellowtail"
  new_fish.weight = 395
  AddToInventory (new_fish)
}

You can do the same with exits, but the command is "create exit".
Like so:

create exit ("out", box_room, room_outside_box, "outdirection")

Note that I specified which direction the exit is twice. The first, "out", is the alias which appears in the "You can go:" display. The last, "outdirection" in this case, is the name of a type that the exit should inherit. The default ones are northdirection, eastdirection, westdirection, updirection, northwestdirection, and so on. This does a couple of things: the map uses it to work out which side of the room to draw the exit on, and it also adds the abbreviated aliases (so the player can type "go nw"). The compass might or might not work with exits whose type isn't set; it can be a little unpredictable.

If you want the player to be able to reenter the box, you'd want to add something like:

create exit ("in", room_outside_box, box_room, "indirection")

there's also a core function CreateBiExits which is supposed to create two exits at once, but I'd advise against using it because it doesn't set the exit type.

create exit doesn't actually return the new exit as far as I'm aware, so if you want to give the exit any other attributes you'll either want to pick a name for it in advance, or find the exit again.
these two pieces of code will do roughly the same thing:

exitname = GetUniqueElementName ("exit")
create exit (exitname, "north", source_room, destination_room, "northdirection")
newexit = GetObject (exitname)

or

create exit ("north", source_room, destination_room, "northdirection")
newexit = GetObject (GetExitByLink (source_room, destination_room))

then you have a variable newexit which you can use to do things such as locking the exit you've just created.
Note that the function GetExitByName is a little misleading, because it gets the name of an exit between those two rooms, not the exit itself.


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums