Quick questions on naming exits in code

I have done this in my Wumpus game, naming the exit to the name of the destination room, but I was naming the exit OF the room I was in and each exit had it's own name...
But, here is my question...
I am in room #1, exits are north, East, and South...
After I go north, I am in room #2, the exits are West and South...
How to I change the north exit in room #1 to say "room #2" and the south exit in room #2 to say "Room #1"
So that, when I enter room #2, it will list the exits as: West and room #1...
(I know this is an easy fix...)


Hmm ... looks like you want a script that runs whenever you go through a door. I'd probably give all the rooms an onexit script:

x = GetExitByLink (this, game.pov.parent)
if (not x = null) {
  x = GetObject (x)
  x.alias = GetDisplayAlias (x.to)
}
x = GetExitByLink (game.pov.parent, this)
if (not x = null) {
  x = GetObject (x)
  x.alias = GetDisplayAlias (x.to)
}

(You could also do this by adding code to the player's changedparent script, using this.parent and oldvalue; you would have to be careful not to break the existing functionality of that script, though)

Or am I misunderstanding you?


You sound like you got it...
But your code has me lost...
Something simple like:
room #1. exit_north.alias="room #2"
for the room I just left... and...
room #2.exit_south.alias="room #1"
for the room I just entered...
Maybe placed in the "Before entering the room:" script so that the door I just came through would have the room name and not the direction.


If you just want to change the north exit of room #1, you could do:

exit_north = GetObject( GetExitByName(Room #1, "north"))
exit_north.alias = "Room #2"

Sorry, I thought you wanted to rename whichever exit the player walked through. For that, I went for the onexit script, because the beforeenter script doesn't know where you came from.

In an onexit script, this is the room you're going from, and game.pov.parent is the room you're going to. So GetExitByLink (this, game.pov.parent) is the exit you went through, and GetExitByLink (game.pov.parent, this) is the other side of the same door.


When put in the onexit script, this is the room you just exited.

So this next line finds the exit between the room you just left and the room you are currently in, and sets it up as x.

x = GetExitByLink (this, game.pov.parent)

This just checks to make sure x exists, making sure the script won't throw an error if it doesn't:

if (not x = null) {

This just changes x from a string to an object.
x = GetObject (x)

And this sets the exit's alias to the alias of the room the exit leads to:
x.alias = GetDisplayAlias (x.to)

CLICK HERE to check it out in an example game with debugging messages, DL:
<!--Saved by Quest 5.7.6404.15496-->
<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="Example (code by mrangel)">
    <gameid>b1109d19-2c86-407b-972b-7ee2da530b2c</gameid>
    <version>1.0</version>
    <firstpublished>2017</firstpublished>
    <start type="script">
    </start>
    <roomenter type="script">
    </roomenter>
  </game>
  <object name="room one">
    <inherit name="editor_room" />
    <usedefaultprefix type="boolean">false</usedefaultprefix>
    <onexit type="script">
      x = GetExitByLink (this, game.pov.parent)
      if (not x = null) {
        msg ("FIRST ONEXIT SCRIPT:")
        msg ("This is the exit the script found: "+x)
        x = GetObject (x)
        msg ("This is the room that exit leads to: "+GetDisplayAlias (x.to))
        msg ("This is the exit object: "+x)
        x.alias = GetDisplayAlias (x.to)
      }
      x = GetExitByLink (game.pov.parent, this)
      if (not x = null) {
        msg ("SECOND ONEXIT SCRIPT:")
        msg ("This is the exit the script found: "+x)
        x = GetObject (x)
        msg ("This is the room that exit leads to: "+GetDisplayAlias (x.to))
        msg ("This is the exit object: "+x)
        x.alias = GetDisplayAlias (x.to)
      }
    </onexit>
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
    <exit alias="north" to="room two">
      <inherit name="northdirection" />
    </exit>
  </object>
  <object name="room two">
    <inherit name="editor_room" />
    <usedefaultprefix type="boolean">false</usedefaultprefix>
    <onexit type="script">
      x = GetExitByLink (this, game.pov.parent)
      if (not x = null) {
        msg (x)
        x = GetObject (x)
        x.alias = GetDisplayAlias (x.to)
      }
      x = GetExitByLink (game.pov.parent, this)
      if (not x = null) {
        msg (x)
        x = GetObject (x)
        x.alias = GetDisplayAlias (x.to)
      }
    </onexit>
    <exit alias="south" to="room one">
      <inherit name="southdirection" />
    </exit>
  </object>
</asl>


EDIT:

Hehehe...

I missed mrangel's post during the 21 minute learning-by-example-game session I had going on there.

(I learn something from mrangel almost every day. Have I told you guys that before? Thanks, mrangel!)


Bingo!!! (I think)... and it works!!!
Now to plug it in and see what it does...
Yes, your two room "game" helps...


Log in to post a reply.

Support

Forums