Just Curious

How do you reference the last exit that the player went through?


K.V.

Here's a link to a few ways you can do it.

The code in my very first post works, and it's what I'm using right now, but there are other posts with alternate methods.

http://textadventures.co.uk/forum/samples/topic/gwlmorbohe6puxrzcfumcg/the-last-room-visited-scripts-function-command


I think that thread talks about keeping track of past rooms that a player has visited. I want to reference the last exit used. Didn't you create a function that does that in one of your recent posts? Thanks.


You'd just have to store the used Exit into an Object (reference/pointer) Attribute (holds a single item only) or an Objectlist Attribute (holds multiple items), as there is an:

http://docs.textadventures.co.uk/quest/functions/allexits.html

Exits are seen/recognized as Objects, as they're able to be stored and returned in an Objectlist Attribute as the above Function does.

so, upon using an Exit, you need to store that Exit into an Attribute, which you can then use it when you need to, and however you want to use it.

pretty much the exact same thing as done with 'Room Objects'


K.V.

You can alter the go script (this is the same method HK described):

<command name="go">
    <pattern type="string"><![CDATA[^go to (?<exit>.*)$|^go (?<exit>.*)$|^(?<exit>north|east|south|west|northeast|northwest|southeast|southwest|in|out|up|down|n|e|s|w|ne|nw|se|sw|o|u|d)$]]></pattern>
    <unresolved>You can't go there.</unresolved>
    <script>
      if (exit.visible) {
        if (exit.locked) {
          msg (exit.lockmessage)
        }
        else if (exit.runscript) {
          if (HasScript(exit, "script")) {
            player.lastExit = exit
            do (exit, "script")
          }
        }
        else if (exit.lookonly) {
          msg ("You can't go there.")
        }
        else {
          if (HasString(exit, "message")) {
            if (not exit.message = "") {
              if (game.clearscreenonroomenter) {
                game.currentexitmessage = exit.message
              }
              else {
                msg (exit.message)
              }
            }
          }
          player.lastExit = exit
          game.pov.parent = exit.to
        }
      }
      else {
        msg ("You can't go there.")
      }
    </script>
  </command>

Room enter script:

if (HasAttribute(player, "lastExit")) {
  if (not player.lastExit = null) {
    msg ("Last exit used: " + player.lastExit)
    msg ("Last exit used's alias: " + player.lastExit.alias)
  }
}

Thanks guys. Modifying the "go" command makes sense as you don't have to modify every exit script in the game. I actually modified the player.changedparent script by adding

player.LastRoom = oldvalue

and using that as a proxy for identifying the last exit the player used. Also works for teleporting! My method won't work if you have multiple exits from room A to room B, but I don't have that in my game.


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

Support

Forums