Running a script for all exits

The Pixie
10 Aug 2011, 08:44
Is there a simple way to have a script run when an exit is used that can be applied across the whole map? I appreciate I can set each exit individually to run a script which can call a single function; I want to set this for all exits in one go (I also want to the script to know what exit it is, and to optionally stop it working).

Specifically, I want to increment time when the player moves from one room to another, say by 5 minutes, unless the exit has a time attribute, in which case it uses that. Also, if an exit has an opening_hours attribute, I want it to be locked at some time of the day. I can do this setting each exit individually to call a function; how do I get calling the function to be the default behaviour?

I hope this makes sense.

Alex
10 Aug 2011, 08:59
You could modify the "defaultexit" type (use the Filter button to show library elements, then copy it into your game), but then all exits would suddenly become script exits, so your script would have to move the player itself, and then any exit that was actually a script exit would override the script from the type.

Probably a better idea would be to modify "defaultplayer" instead. This has a "changedparent" attribute which is a script that runs every time the player moves room - it's what prints the room description. You could add some code in there. All that code currently does is run the OnEnterRoom function, so alternatively you could modify that function instead.

(In fact this might be a nice little Core library feature - it might be good to expose the ability to run a script every time the player changes room. The OnEnterRoom function could be updated to run a script attribute on the "player" object, which could be exposed via one of the CoreEditorObject*.aslx files to show a "When the player moves" script editor.)

The Pixie
10 Aug 2011, 21:59
I do not think changing default player will work, because I want to have access to the exit. I will be more specific so this is clearer. I want to have a game clock, with time increasing by 5 minutes whenever the player moves to another room, unless that exit has a time attribute, in which case it increase by that instead. To do that, the script needs to know what exit was used.

I am hoping to put this in a library, and the modification to defaultexit sounds to drastic for a general purpose library (though might work for what I need).

Pertex
11 Aug 2011, 07:41
You could do this by using a turnscript. You need a global variable "oldplace" to save the actual room of the player. Within the turnscript you compare oldplace with player.parent. If they are different, the player has changed the room.
To have different times, you can use a dictionary.

Here is an example what I mean:

room1 with exit to room2 takes 10 minutes
room1 with exit to room3 takes 23 minutes

<times type="stringdictionary">
room1_room2=10
room1_room3=23
</times>


With oldplace and player_parent you can create the key of an entry of the dictionary