Global Before Enter Script

Forgewright
18 Apr 2020, 18:32

I need to add player.lastroom = player.parent to all room's 'before enter script'
at one time.
Is there a room list saved by Quest?
oh wait...
In Start Script I add:

foreach (obj, AllRooms ()) {
  obj.beforeenter => {
    player.lastroom = player.parent
  }
}

I know we've hashed this out years ago but I can't find it.
Isn't this the easiest way to store the last room the player was in?


Dcoder
18 Apr 2020, 19:27

Just put it in the player.changedparent script. Something like:

player.lastroom = oldvalue

Then, every time the player moves, player.lastroom will automatically record the previous room (oldvalue contains the change script's previous object value).


Forgewright
18 Apr 2020, 20:23

I saw the changedparent script but still didn't understand exactly what it was doing. I will try it.
EDIT: Indeed that works.
Thanks


Forgewright
18 Apr 2020, 20:38

So if I want the last value of any object.attribute that changed in the game I can add a "changedwhatever" attribute to that object and store that value? I understood that Quest recognized any attribute that started with "changed", but never new exactly what it did.
Simply saves old values...Hmm


mrangel
18 Apr 2020, 22:09

Might be worth noting that there is a script game.roomenter which is run whenever the player changes room. It triggers after the room description, but before the room's enter script.

However, in this case changedparent is a lot better because that script has access to the previous value of the variable.

(Actually, that's something I should suggest for the next version of Quest: the old and new rooms should be passed to any scripts that are run. It would be extremely simple to do, and make it a lot easier to do stuff like this)


Dcoder
18 Apr 2020, 22:54

@Forgewright -
A change script just kicks in immediately whenever its underlying attribute changes values, e.g., when the value of player.parent changes, then the player.changedparent script automatically runs. oldvalue is a Quest special variable that temporarily (within that change script) records the value of that attribute before the change.