move player script?

I need a script to move a player in a direction (north, for instance), no matter what room the player is in when this happens. Maybe, I can find one. I am still looking.


The first thing that comes to mind:

name = GetExitByName (game.pov.parent, "north")
if (TypeOf (name) = "string") {
  exit = GetObject (name)
  if (exit = null or not HasObject (exit, "to")) {
    // something went wrong; or the exit doesn't go anywhere
  }
  else {
    game.pov.parent = exit.to
  }
}
else {
  // there is no north exit
}

(Note that if you want to run exit scripts, you'd need to account for that too)


If you want it to only consider exits that are visible and not locked, you could probably do something like:

exit = PickOneObject (FilterByType (ScopeExits (), "northdirection"))
if (not exit = null) {
  do (go, "script", QuickParams ("exit", exit))
}
else {
  // Whatever you want it to do if there isn't a north exit
}

Which basically calls the "go" command as if the player had used it.
In this case I used PickOneObject to get the object from an objectlist with one member. This isn't very nice to the server, because it generates an unnecessary random number, but seems worth it to make the code simpler (and behaves sanely if there are multiple exits, without having to make a special case for it).

Here, we're getting a list of available exits and filtering it to see which of them inherit the northdirection type. In the previous example, I looked for exits whose alias is "north". These normally give the same result, but can differ.

In the previous example I set the player's location to the exit's destination; in this one I used do to run the script for the "go" command. These will behave differently in cases where the exit is locked or has a script on it. Choose the one that best fits what you want to do.

You could use either method to find the exit, and either method to activate it, to get the behaviour you want.


Amazing! The first one works really well. It sent me from one room in my game all the way to the top before it stopped, not stopping for breaks. I like it. Thanks.
All of my exits are visible and unlocked, so the first is just what I needed.


My game gave me an error message
I just don't know if it was caused by this, as it was the only major change I had made.
I accidentally deleted the copy and paste of it, by accidentally closing the screen while going back to look for the cause, but it was, I think this:
Error something cannot execute (GetAllChildObjects) - and maybe - parameters - and room - and went on to say that this was because the game had been edited and would perhaps not "necessarily" "enumerate".
I was at 6,0 the top of the map , but had last moved west. I may have pressed north there, but it did not say so. Maybe that was not in the error message. I don;t know if it is because of this script.
I may have pressed the up arrow in a northernmost room. I was using the first script. I may just need to modify it to not work with every enter. ( I would for the game, either way.)


I am not still having that difficulty. I am running it on diagonals, now. It may have just interfered with the keyboard to compass document.


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums