how to use exit.script

I am making a show menu () that locates all exits in a room and when the exit name is clicked then it is supposed to use the script that is supposed to run when the player attempts to use an exit (located in exit.script). I have failed with both do and invoke in the following attempt:

  show menu ("Move to where?", menulist, true) {
    foreach (exit_name, menulist) {
      current_exit = GetObject (exit_name)
      if (current_exit.alias <> null) {
        if (result = current_exit.alias) {
          invoke (current_exit.script)
        }
      }
      else {
        if (result = current_exit.name) {
          do (current_exit, "script")
        }
      }
    }
  }

Each exit has a pretty unique script attached to them and I really hope not to have to test each exit's name in the if(result) block and copy each script in. How can I access the exit.script with a function?


I can't tell what you're trying to do here.

GetObject implies that menulist is a list of object names. So comparing the result to an alias seems weird.

If you have a list of object names, you would want:

show menu ("Move to where?", menulist, true) {
  current_exit = GetObject (result)
  do (current_exit, "script")
}

If some of them are aliases, this is harder because you can't use GetObject on an alias, so you never have an object to look at its alias. But you say they're all in a room; so it would be easier to loop over all exits and find one in this room that has this name-or-alias:

show menu ("Move to where?", menulist, true) {
  foreach (exit, AllExits()) {
    if (Contains (room, exit) and result = GetDisplayAlias (exit)) {
      do (exit, "script")
    }
  }
}

You're right. I deleted the alias check. I now realize that the exit alias is different from a room alias. Thanks for pointing that out. Unfortunately I am still unable to activate each exit's exit script.

The goal of this particular show menu() is to provide the user with an interface to which they can select available locations and exits and then immediately go to such location if they are able. The check for whether they are able to or not is in the location object itself. The particular exit I am testing this with is using an otherwise pointless script that literally just changes the player's parent to the exit's destination room. Using the exit with verbs works obviously but I cannot figure out how to call the script through a function.


Does it just not work, or does it give an error message?

My guess is that the value in menulis isn't exactly the same as the name of the exit (or the alias if you're using the second script I suggested).

If you're still having trouble, could you show the script you're currently using, including the part that generates menulist?


I was able to solve it. You were correct in noting that the name in menulist was not exactly the same as the name of the exit. Thanks again for taking the time to help me.


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

Support

Forums