Making a object move to a specific direction using command

In making a game with horse riding,
You know how on the side of the text box like Once: or B (Bold)

Is there a way I can use that to make a object move to a direction? With a command like:

Ride horse west
Like where west is it kind of be like [direction]


It will be very much like this:
https://textadventures.co.uk/forum/quest/topic/guvemyyxheio3tiogk6m9q/push-object-direction

And the sequel:
http://textadventures.co.uk/forum/quest/topic/2pwcb_0rikapdrldyr2yva/push-object-direction


K.V.

Pixie's suggestion is the best solution.


If you want to actually ride the horse around, you could try this (it might work):

http://textadventures.co.uk/forum/samples/topic/chdetokj-0gyxr-abcmktg/horselib


This is new code, and there may be bugs!

Be sure to test this on a copy of your game, not the game itself!!!


K.V.

A simple solution which does not include actually riding the horse around (which I am stealing from NecroDeath) would be this:

Create a command: ride_horse_cmd

The pattern:

ride #object# #exit#

The script:

if (not object = horse) {
  msg ("You can't ride " + object.article + ".")
}
else {
  if (exit.visible) {
    if (exit.locked) {
      msg (exit.lockmessage)
    }
    else if (exit.runscript) {
      if (HasScript(exit, "script")) {
        // Move the horse first, so it shows up in the next room's description.
        MoveObject (object, exit.to)
        do (exit, "script")
      }
    }
    else if (exit.lookonly) {
      msg ("You can't go there.")
    }
    else {
      if (HasString(exit, "message")) {
        if (not exit.message = "") {
          if (game.clearscreenonroomenter) {
            game.currentexitmessage = exit.message
          }
          else {
            msg (exit.message)
          }
        }
      }
      // Move the horse first, so it shows up in the next room's description.
      MoveObject (object, exit.to)
      game.pov.parent = exit.to
    }
  }
  else {
    msg ("You can't go there.")
  }
}

This part of the code looks odd:

      if (HasScript(exit, "script")) {
        // Move the horse first, so it shows up in the next room's description.
        MoveObject (object, exit.to)
        do (exit, "script")
      }
    }

In a lot of cases, an exit with a script might prevent you from travelling. In this case, you would likely want:

      if (HasScript(exit, "script")) {
        // Move the horse first, so it shows up in the next room's description.
        MoveObject (object, exit.to)
        do (exit, "script")
        // Move the horse back if the player hasn't moved
        if (game.pov.parent = exit.parent) {
          object.parent = exit.parent
        }
      }
    }

It might also make sense for an exitscript to get a parameter identifying the horse in this case.


K.V.

Thanks, mrangel!

I was supposed to make a note about the exits having scripts which might do something other than move the player to the target room, but I completely forgot. I'm glad I did, too, because your solution to that is much better than what I was thinking about doing!


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

Support

Forums