Setting alias via a variable.

Carrot
06 Jul 2013, 09:55
I am building a maze, with several identical rooms. Rather than set up each rooms alias individually I would like it to be dynamic - so that if I change exits around I don't have to worry about forgetting the alias.

I have tried several different types of expression in the alias field, and have even tried setting the alias attribute of the room with a script.

The problem is the alias either remains blank, prints the room name (i.e. room01) or prints the contents of my script instead of returning the value game.pov.parent.RoomType.

Liam315
06 Jul 2013, 10:41
Changing the attribute type of "alias" from string to script in order to make the name dynamic will also require you to make changes to some default functions. You'll have to have a look and experiment a bit as it depends on how your room descriptions are generated, but functions in the general area of GetDisplayAlias, GetRoomDescription etc. are the ones you're looking for. In the script, you'll notice that they use the script functions "HasString." You'll need to include lines that account for the possibility of the room alias being a script. e.g. if... HasScript(game.pov.parent, "alias") then do (game.pov.parent, "alias").

Your other option is to set the alias to anything before the game, and use scripts once the game has started to change them as necessary. I'm not 100% sure of the effect you're trying to achieve so I can't really be any more helpful than that.

Carrot
06 Jul 2013, 10:54
OK, it is half working (I think).

I changed "game.pov.parent.RoomType" to "game.pov.parent.alias"

I am not sure this has had much of an effect really, but in theory I no longer need to call the RoomType.

Problem is, the alias shows up fine on a look command, or the second time you enter a room.

I somehow need to call this script before entry, but it is part of an inherited type.

Carrot
06 Jul 2013, 10:57
Liam315 wrote:Changing the attribute type of "alias" from string to script in order to make the name dynamic will also require you to make changes to some default functions. You'll have to have a look and experiment a bit as it depends on how your room descriptions are generated, but functions in the general area of GetDisplayAlias, GetRoomDescription etc. are the ones you're looking for. In the script, you'll notice that they use the script functions "HasString." You'll need to include lines that account for the possibility of the room alias being a script. e.g. if... HasScript(game.pov.parent, "alias") then do (game.pov.parent, "alias").

Your other option is to set the alias to anything before the game, and use scripts once the game has started to change them as necessary. I'm not 100% sure of the effect you're trying to achieve so I can't really be any more helpful than that.


Well in this instance, the rooms alias ill not change during a game - it was more so I didn't have to type in the alias for a room while designing it (corner, t-junct, x-road, etc..) and risk forgetting to change it if I add or remove an exit.

Carrot
06 Jul 2013, 11:08
Here is the code I am using, this affects all rooms which inherit it.

  <type name="BaseRoom">
<marked type="int">0</marked>
<RoomType type="string"></RoomType>
<RoomDescription type="string"></RoomDescription>
<description type="script"><![CDATA[
// Then in your description code.
exitlist = NewList()
if (HasExit(0)) {
list add (exitlist, "forward")
}
if (HasExit(1)) {
list add (exitlist, "right")
}
if (HasExit(2)) {
list add (exitlist, "back")
}
if (HasExit(3)) {
list add (exitlist, "left")
}
// Then generate the string from it
// Stolen from the Quest core's FormatExitList function
s = "You can go "
count = 0
length = ListCount(exitlist)
foreach (exit, exitlist) {
s = s + exit
count = count + 1
if (count = length-1) {
s = s + " or "
}
else if (count < length) {
s = s + ", "
}
}
s = s + "."
if (count = 1) {
game.pov.parent.alias = "Dead End"
game.pov.parent.RoomDescription = "You are standing at a dead end "
}
else if (count = 2) {
if (HasExit(0)) {
game.pov.parent.alias = "Long Corridor"
game.pov.parent.RoomDescription = "You are walking along a very long corridor "
}
else {
game.pov.parent.alias = "Sharp Bend"
game.pov.parent.RoomDescription = "You have reached a sharp bend in the corridor "
}
}
else if (count = 3) {
game.pov.parent.alias = "T-Junction"
game.pov.parent.RoomDescription = "You are standing at a T-Junction "
}
else if (count = 4) {
game.pov.parent.alias = "Crossroads"
game.pov.parent.RoomDescription = "You are standing at a crossroads "
}
msg (game.pov.parent.RoomDescription + "in a maze of dark, twisty passages that all look the same.")
if (game.pov.parent.marked = 0) {
}
else {
msg ("The number " + game.pov.parent.marked + " has been drawn on to the wall in marker pen.")
}
msg (s)
]]></description>
</type>
<function name="ChangeRoom" parameters="dir">
room = game.pov.parent
if (HasAttribute(room, "exit" + dir)) {
newroom = GetAttribute(room, "exit" + dir)
// Set new player direction.
game.pov.dir = GetInt(room, "exitdir" + dir)
// msg ("Debug: move to room " + newroom.name + ", facing dir " + game.pov.dir)
if (newroom = room) {
// Same room. Force room description dump, etc
OnEnterRoom (room)
}
else {
// New room. Just move.
game.pov.parent = newroom
}
}
else {
msg ("You can't go that way.")
}
</function>
<function name="HasExit" parameters="dir" type="boolean">
dir = (game.pov.dir + dir) % 4
return (HasAttribute(game.pov.parent, "exit"+dir))
</function>

jaynabonne
06 Jul 2013, 21:27
You could put the alias-setting code in a beforefirstenter script instead. Then it will run once before the room is entered.