advanced script command in case a player leaves a room
oblomov
11 Nov 2009, 22:21its a pretty tiny thing, but anyway it would have helped me lots of times allready..
it allready exists the possibility of an advanced script command in case the player "enters" the room. but there is no option for a script in case the player "leaves" the room..
it allready exists the possibility of an advanced script command in case the player "enters" the room. but there is no option for a script in case the player "leaves" the room..
Wonderjudge
12 Nov 2009, 02:32Technically there is because you can script all your exits. Easy to to if you only have one exit, harder with lots.
Wonderjudge.
Wonderjudge.
Alex
12 Nov 2009, 13:21An easier solution might be to create an "afterturn" script which sets an "oldroom" variable to the value of #quest.currentroom#.
Compare these values at the start of your script, and if they're different, see if #oldroom# has a "leaveroom" action - if so, run it. Then you can create a "leaveroom" action for any room which will be run after the player has left it.
Compare these values at the start of your script, and if they're different, see if #oldroom# has a "leaveroom" action - if so, run it. Then you can create a "leaveroom" action for any room which will be run after the player has left it.
Overcat
12 Nov 2009, 18:38There are three example game files to come. The first is in this reply. If anyone has suggestions on how to improve these methods, let us all know!
As per Alex's suggestion above:
As per Alex's suggestion above:
define options
debug on
panes disabled
end define
define game <AfterLeave>
asl-version <410>
gametype singleplayer
start <Home>
game version <1.0>
game author <J. Dobson>
game copyright <© 2009 JDG Inc.>
background <black>
default fontname <arial>
default fontsize <10>
foreground <White>
'Set your 'last room' variable here, equal to the start tag above.
startscript {
set string <quest.lastroom; Home>
}
'This script implements the AfterLeave action on a room, if the
'action exists on a room.
afterturn {
if (#quest.currentroom# <> #quest.lastroom#) then {
if action <#quest.lastroom#; AfterLeave> then {
doaction <#quest.lastroom#; AfterLeave>
}
set <quest.lastroom; #quest.currentroom#>
}
}
end define
define room <Frontyard>
alias <Frontyard>
look <You're in your frontyard.>
south <Home>
'This overwrites the default AfterLeave script defined in the 'defaultroom'
'type below.
action <AfterLeave> {
msg <|n(Over-written AfterLeave script fired for $thisobject$.)>
}
end define
define room <Home>
alias <Home>
look <You're home.>
north <Frontyard>
'Even though this room does not have it's own AfterLeave action defined,
'it will inherit one from the 'defaultroom' type. See below.
end define
'This is the definition for 'defaultroom'. Anything you define here
'will automatically be inherited by any other room in your game. Because
'the AfterLeave action has been defined here, every room will now have this
'action, even if you omit this action from any room particular room.
define type <defaultroom>
action <AfterLeave> {
msg <|n(Default AfterLeave script fired for $thisobject$)>
}
end define
Overcat
12 Nov 2009, 18:40For an example with both BeforeLeave and AfterLeave functionality, see next. It is assumed that one might want to restrict player movement with BeforeLeave, so it has been built to allow this.
define options
debug on
panes disabled
end define
define game <BeforeAndAfterLeave>
asl-version <410>
gametype singleplayer
start <Home>
game version <1.0>
game author <J. Dobson>
game copyright <© 2009 JDG Inc.>
background <black>
default fontname <arial>
default fontsize <10>
foreground <White>
'Set your 'last room' variable here, equal to the start tag above.
startscript {
set string <quest.lastroom; Home>
}
'This script implements the AfterLeave action on a room
afterturn {
if (#quest.currentroom# <> #quest.lastroom#) then {
doaction <#quest.lastroom#; AfterLeave>
set <quest.lastroom; #quest.currentroom#>
}
}
'This script implements the BeforeLeave action on a room.
beforeturn {
select case <#quest.command#> {
case <north; south; west; east; up; down; northwest; northeast; southwest; southeast> {
doaction <#quest.currentroom#; BeforeLeave>
if not property <#quest.currentroom#; isLeavable> then dontprocess
}
}
}
end define
'These synonyms are required in order to make the BeforeLeave functionality
'effective, even though Quest already understands the short-forms for travel
'directions.
define synonyms
n = north
s = south
e = east
w = west
u = up
d = down
nw = northwest
ne = northeast
sw = southwest
se = southeast
end define
define room <Home>
alias <home>
prefix <your>
look <You're home.>
north <Frontyard>
'Even though this room does not have it's own AfterLeave action defined,
'it will inherit one from the 'defaultroom' type. See below.
'Same goes for the BeforeLeave action, which is also inherited.
end define
define room <Frontyard>
alias <front yard>
prefix <your>
look <You're in your frontyard. It's damn cold out here.>
south <Home>
define object <apple>
take
alias <apple>
prefix <an>
article <it>
look <Yummy.>
end define
'This overwrites the default BeforeLeave script defined in the 'defaultroom'
'type below.
action <BeforeLeave> {
if here <apple> then {
msg <You should take the apple before you leave.>
property <$thisobject$; not isLeavable>
}
else {
property <$thisobject$; isLeavable>
}
}
'This overwrites the default AfterLeave script defined in the 'defaultroom'
'type below.
action <AfterLeave> {
set string <this; $thisobject$>
msg <|n(You've just left #(this):prefix# #@this#, and thank goodness - it was cold out there!)>
}
end define
'*****THE DEFAULTROOM TYPE********
'This is the definition for 'defaultroom'. Anything you define here
'will automatically be inherited by every other room in your game. For instance,
'because the AfterLeave action has been defined here, every room will now have
'this action, even if you do not define this action in any particular room.
define type <defaultroom>
'isLeavable
action <BeforeLeave> {
property <$thisobject$; isLeavable>
}
action <AfterLeave> {
set string <this; $thisobject$>
msg <|n(You've just left #(this):prefix# #@this#.)>
}
end define
Overcat
12 Nov 2009, 18:41And then, because you might as well extend this to the inevitable, see next for an example that gives you BeforeLeave, AfterLeave, BeforeEnter, and AfterEnter functionality. BeforeEnter has also been built to allow the blocking of player movement, if the game author so wishes.
define options
debug on
panes disabled
end define
define game <BeforeAndAfterLeave>
asl-version <410>
gametype singleplayer
start <Home>
game version <1.0>
game author <J. Dobson>
game copyright <© 2009 JDG Inc.>
background <black>
default fontname <arial>
default fontsize <10>
foreground <White>
'Initialize your 'last room' variable here, equal to the start tag above.
startscript {
set string <quest.lastroom; Home>
}
'This script implements our own room description formatting, and
'the BeforeEnter, AfterEnter, and AfterLeave actions of a room.
description {
if (#quest.lastroom# <> #quest.currentroom#) then {
doaction <#quest.currentroom#; BeforeEnter>
if not property <#quest.currentroom#; isEnterable> then {
outputoff
goto <#quest.lastroom#>
outputon
}
else {
doaction <#quest.lastroom#; AfterLeave>
do <RoomDescription>
doaction <#quest.currentroom#; AfterEnter>
}
}
else {
do <RoomDescription>
}
}
'This script implements the BeforeLeave action on a room.
beforeturn {
select case <#quest.command#> {
case <north; south; west; east; up; down; northwest; northeast; southwest; southeast> {
doaction <#quest.currentroom#; BeforeLeave>
if not property <#quest.currentroom#; isLeavable> then dontprocess
}
}
}
end define
'A procedure to describe rooms.
define procedure <RoomDescription>
set <quest.lastroom; #quest.currentroom#>
msg <|b|cr$capfirst(#(quest.currentroom):prefix#)$ $capfirst(#(quest.currentroom):alias#)$|xb|cb>
msg <>
msg <#quest.lookdesc# |xn>
if ($lengthof(#quest.doorways#)$ > 0) then {
msg <You can go #quest.doorways#.>
}
else {
msg <>
}
if ($lengthof(#quest.formatobjects#)$ > 0) then {
msg <>
msg <You can see #quest.formatobjects#.>
}
end define
'These synonyms are required in order to make the BeforeLeave functionality
'effective, even though Quest already understands the short-forms for travel
'directions.
define synonyms
n = north
s = south
e = east
w = west
u = up
d = down
nw = northwest
ne = northeast
sw = southwest
se = southeast
end define
define room <Home>
alias <home>
prefix <your>
look <You're in the warm comfort of your house.>
north <Frontyard>
'Even though this room does not have it's own AfterLeave action defined,
'it will inherit one from the 'defaultroom' type. See below.
'Same goes for the BeforeLeave, BeforeEnter, and AfterEnter actions.
end define
define room <Frontyard>
alias <front yard>
prefix <your>
look <You're in your frontyard.>
south <Home>
north <Street>
define object <apple>
take
alias <apple>
prefix <an>
article <it>
look <Yummy.>
end define
'This overwrites the default BeforeEnter script defined in the 'defaultroom'
'type below.
action <BeforeEnter> {
'If the player has the apple, remove the 'isEnterable' property from this
'room, thereby making it non-enterable. You should message the player
'something relevant in this case.
if got <apple> then {
msg <You should leave the apple behind before you go to the front yard.>
property <$thisobject$; not isEnterable>
}
else {
property <$thisobject$; isEnterable>
}
}
'This overwrites the default AfterEnter script defined in the 'defaultroom'
'type below.
action <AfterEnter> {
msg <Gosh, it's cold out here.>
}
'This overwrites the default BeforeLeave script defined in the 'defaultroom'
'type below.
action <BeforeLeave> {
'If the apple here, remove the 'isLeavable' property from this room,
'thereby making it non-leave-able. You should message the player
'something relevant in this case.
if here <apple> then {
msg <You should take the apple before you leave.>
property <$thisobject$; not isLeavable>
}
else {
property <$thisobject$; isLeavable>
}
}
'This overwrites the default AfterLeave script defined in the 'defaultroom'
'type below.
action <AfterLeave> {
set string <this; $thisobject$>
msg <|n(You've just left #(this):prefix# #@this#, and thank goodness - for it is not a very pretty front yard, and it offends your eyes.)>
}
end define
define room <Street>
alias <street>
prefix <the>
look <You're standing on a barren street.>
south <Frontyard>
'Just like the Home room, this room inherits all of the stuff
'from the 'defaultroom' type definition, directly below.
end define
'*****THE DEFAULTROOM TYPE********
'This is the definition for 'defaultroom'. Anything you define here
'will automatically be inherited by every other room in your game. For instance,
'because the AfterLeave action has been defined here, every room will now have
'this action, even if you do not define this action in any particular room.
define type <defaultroom>
action <BeforeEnter> {
'The property 'isEnterable' is set on a room by default to indicate
'that it is, indeed, enterable.
property <$thisobject$; isEnterable>
}
action <AfterEnter> {
set string <this; $thisobject$>
msg <|n(You've just entered #(this):prefix# #@this#.)>
}
action <BeforeLeave> {
'The property 'isLeavable' is set on a room by default to indicate
'that it is, indeed, leave-able.
property <$thisobject$; isLeavable>
}
action <AfterLeave> {
set string <this; $thisobject$>
msg <|n(You've just left #(this):prefix# #@this#.)>
}
end define