Enumerate Exits with their destination?
MaxVK
24 Aug 2009, 09:35Hi, I'm trying to list all of the exits in a room, along with their destinations so that I can format the text nicely myself, however I have run into a problem with the latest change to the way exits are handled.
The code Iv found with searching is all related to the '.places. etc, but this has changed and I cant work out how to do it.
Example: the player enters Room1. I manually print the name of the room and the description, but I would like to also list the exits like this:
You may go:
North to Room2
West to Room3
UP the stairs
This would (hopefully) include the ability to format the output so that the directions are in Bold and the destination name is in blue. Iv seen the information that I want in the debug window, but for the life of me I cant work out how to get to it myself.
Any help please?
regards
Max
The code Iv found with searching is all related to the '.places. etc, but this has changed and I cant work out how to do it.
Example: the player enters Room1. I manually print the name of the room and the description, but I would like to also list the exits like this:
You may go:
North to Room2
West to Room3
UP the stairs
This would (hopefully) include the ability to format the output so that the directions are in Bold and the destination name is in blue. Iv seen the information that I want in the debug window, but for the life of me I cant work out how to get to it myself.
Any help please?
regards
Max
MaDbRiT
27 Aug 2009, 19:47Hi Max
Because Quest doesn't have a way of easily reading where a directional exit leads to, I can only think of two ways to get the effect you want.
One is to move the player around invisibly - visiting all the adjacent rooms to collect the location detail - but that is messy and creates a lot of potential for nasty problems.
Two, (and what I'd do if i wanted to create this effect) is to create properties for each potential location at design time, then read them to output below the room description. I've mocked up a three location example (code below) which only deals with the four main points of the compass, but it could easily be extended for the intermediate directions and up/down.
Hopefully how this works is pretty easy to follow, but do feel free to ask if it isn't clear.
Al (MaDbRiT)
if you save all the code as an .asl file it should be a runnable demo in Quest
Because Quest doesn't have a way of easily reading where a directional exit leads to, I can only think of two ways to get the effect you want.
One is to move the player around invisibly - visiting all the adjacent rooms to collect the location detail - but that is messy and creates a lot of potential for nasty problems.
Two, (and what I'd do if i wanted to create this effect) is to create properties for each potential location at design time, then read them to output below the room description. I've mocked up a three location example (code below) which only deals with the four main points of the compass, but it could easily be extended for the intermediate directions and up/down.
' Quest 4.1 ASL Template
define game <Exit Demo>
asl-version <410>
gametype singleplayer
game version <1.0>
game author <MaDbRiT>
game copyright <© 2009 AGB>
game info <Demo.>
start <library>
description {
do <Describe_Proc>
}
end define
define room <library>
prefix <the>
properties <northto=the |cl|bstoreroom.|xb|cb; southto=z; westto=z; eastto=z>
north <storeroom>
end define
define room <storeroom>
prefix <the>
properties <northto=z; southto=the |cl|blibrary.|xb|cb; westto=the |cl|bboilehouse.|xb|cb; eastto=z>
south <library>
west <boilerhouse>
end define
define room <boilerhouse>
prefix <the>
properties <eastto=the |cl|bstoreroom.|xb|cb; southto=z; northto=z; westto=z>
east <storeroom>
end define
define procedure <Describe_Proc>
set string <Proc_indescription;$gettag(#quest.currentroom#;indescription)$>
if is <#Proc_indescription#;> then {
msg <|nYou are in $gettag(#quest.currentroom#;prefix)$ |b|cl#quest.currentroom#.|cb|xb|xn>
}
else {
msg <|n#Proc_indescription#$gettag(#quest.currentroom#;prefix)$ |b|cl#quest.currentroom#.|cb|xb|xn>
}
msg <|n>
set string <My_Exits;You can go...>
if (#(quest.currentroom):northto#<>z) then {
set <My_Exits;#My_Exits# |n|i|crNorth |cb|xito #(quest.currentroom):northto#>
}
if (#(quest.currentroom):southto#<>z) then {
set <My_Exits;#My_Exits# |n|i|crSouth |cb|xito #(quest.currentroom):southto#>
}
if (#(quest.currentroom):eastto#<>z) then {
set <My_Exits;#My_Exits# |n|i|crEast |cb|xito #(quest.currentroom):eastto#>
}
if (#(quest.currentroom):westto#<>z) then {
set <My_Exits;#My_Exits# |n|i|crWest |cb|xito #(quest.currentroom):westto#>
}
if not ( #My_Exits# = You can go...) then {
msg <#My_Exits#>
}
end define
define text <intro>
Enter intro text here
end define
define text <win>
Enter win text here
end define
define text <lose>
Enter lose text here
end define
Hopefully how this works is pretty easy to follow, but do feel free to ask if it isn't clear.
Al (MaDbRiT)
if you save all the code as an .asl file it should be a runnable demo in Quest
MaxVK
27 Aug 2009, 20:45Thanks Al, Ill give that a go later on.
regards
Max
regards
Max
Arbutus
01 Oct 2009, 06:01I threw this together in QDK for fun. For each exit in the current room, it sets variables so you can access the names of the rooms to which they point.
Because Quest can only have one variable in a property read (eg. #(variable):property# NOT #(variable1):(variable2)#) I had to use a Select Case to hard code the exit directions to read those properties. The code does not account for missing room prefixes and fails if the exit is a SCRIPT instead of a room name. But if you have room prefixes and all exits are just room names it works fine. You can even use this to read room descriptions or any other room property if you wanted.
Because Quest can only have one variable in a property read (eg. #(variable):property# NOT #(variable1):(variable2)#) I had to use a Select Case to hard code the exit directions to read those properties. The code does not account for missing room prefixes and fails if the exit is a SCRIPT instead of a room name. But if you have room prefixes and all exits are just room names it works fine. You can even use this to read room descriptions or any other room property if you wanted.
Print "You may go:"
For each exit in "#quest.currentroom#"
Change the contents of numeric variable "i" to "$instr(#quest.thing#;.)$"
Decrement "i"
Change the contents of string "room" to "$left(#quest.thing#;%i%)$"
Increment "i" by "2"
Change the contents of string "exit" to "$mid(#quest.thing#;%i%)$"
Print "#exit# to #(room):prefix# [NO NEW LINE]"
Select Case "#exit#" {
Case "north" : Print "#(room):north#"
Case "south" : Print "#(room):south#"
Case "east" : Print "#(room):east#"
Case "west" : Print "#(room):west#"
Case "northeast" : Print "#(room):northeast#"
Case "southeast" : Print "#(room):southeast#"
Case "northwest" : Print "#(room):northwest#"
Case "southwest" : Print "#(room):southwest#"
Case "up" : Print "#(room):up#"
Case "down" : Print "#(room):down#"
Case "out" : Print "#(room):out#"
} }
Overcat
01 Oct 2009, 12:33Because Quest can only have one variable in a property read (eg. #(variable):property# NOT #(variable1):(variable2)#) ...
Actually, in the ASL Documentation -> Built-in Functions -> Obsolete Functions there is this:
$objectproperty(object name; property name)$
Returns the value of the specified property of the specified object. Returns "!" and reports an ASL error if the specified object or property does not exist. This function is obsolete as it is equivalent to using #object:property# - see Reading Properties for more information.
This function is far from obsolete (as has been pointed out before), for exactly the reason you've described above. Now both the object and the property can be variables:
$objectproperty(#object#; #property#)$
I can see, however, that you are using QDK, so I'm not sure (since the function is designated as obsolete) if $objectproperty$ is available through the GUI. Here's a shortened, hand-coded version, using your same technique, Arbutus:
description {
msg <|b#(quest.currentroom):alias#|xb|n>
msg <#(quest.currentroom):look#|n>
for each exit in <#quest.currentroom#> {
set numeric <i; $lengthof(#quest.thing#)$ - $instr(#quest.thing#;.)$>
set string <s; $right(#quest.thing#; %i%)$>
msg <|b$capfirst(#s#)$:|xb |cl#(quest.thing):to#|cb>
}
}
}
Granted, I haven't had to use $objectproperty()$ in this case, because exits have a "to" property. Below is an attached demo ASL file, which anyone interested can just run, and then take a peek into. Very simple!
Overcat
01 Oct 2009, 20:24Oh, and by the way, Al - what is $gettag$? T'isn't in the documentation. Same functionality as $objectproperty$?
And "if is <#var#;#value#>" ain't in the documentation either...I assume this is equivalent to "if (#var# = #value#)"?
And "if is <#var#;#value#>" ain't in the documentation either...I assume this is equivalent to "if (#var# = #value#)"?