RPG::MoveRoute

Hi, I was wondering why my move route command doesn't work in Ruby.

i = $game_variables[86]e = $game_map.eventsmove_route = RPG::MoveRoute.newmove_route.repeat = falsemove_route.skippable = falsem = RPG::MoveCommand.newm.code = 25move_route.list.insert(0,m.clone)e.force_move_route(move_route)The event is supposed to turn toward the player with no repeats and skips, but nothing happens.

Edit: I checked the variable that says which event this is and its correct, otherwise other stuff that I programmed wouldn't have done anything as well.
You don't need to do this via script. You can simply do a Set Move Route and check the Repeat button, with a Turn Toward Player command. When you want them to stop "following" the player's movement, just issue another Set Move Route with no movement commands and it will cancel it out.


I don't have Ace in front of me now to see why it's not working, but the fact that you've got move_route.repeat = false might be a good starting point.


But don't do it in a script unless you really have to.
You don't need to do this via script. You can simply do a Set Move Route and check the Repeat button, with a Turn Toward Player command. When you want them to stop "following" the player's movement, just issue another Set Move Route with no movement commands and it will cancel it out.

I don't have Ace in front of me now to see why it's not working, but the fact that you've got move_route.repeat = false might be a good starting point.

But don't do it in a script unless you really have to.
Yes, what I'm doing is checking if the player is within 2 units of a single event out of tens of them on a map. If this is true then they face toward the player (once) and so on. Making the event id a plug and check is needed in this situation.

The repeat attribute isn't the problem, setting it to true isn't what I need anyway.
Not sure what's wrong there, but I know you need a MoveCommand with code 0 to end the the route.
You don't need to do this via script. You can simply do a Set Move Route and check the Repeat button, with a Turn Toward Player command. When you want them to stop "following" the player's movement, just issue another Set Move Route with no movement commands and it will cancel it out.

I don't have Ace in front of me now to see why it's not working, but the fact that you've got move_route.repeat = false might be a good starting point.

But don't do it in a script unless you really have to.
Ah! I got somewhere though...I have multiple amounts of blocks of this code through out the script. I took all but one out and it seems to work. Just like you said, they might be canceling out?

The problem is I don't know exactly how to make it a list of commands :/
Ah! I got somewhere though...I have multiple amounts of blocks of this code through out the script. I took all but one out and it seems to work. Just like you said, they might be canceling out?

The problem is I don't know exactly how to make it a list of commands :/
i = $game_variables[86]e = $game_map.eventsmove_route = RPG::MoveRoute.newmove_route.repeat = repeatmove_route.skippable = skippablemove_route.wait = waitmove_route.list = []move_route.list << RPG::MoveCommand.new(Game_Character::ROUTE_TURN_TOWARD)move_route.list << RPG::MoveCommand.new(Game_Character::ROUTE_END)e.force_move_route(move_route)you can add as many commands as you need, like this:

Code:
move_route.list << RPG::MoveCommand.new(Game_Character::ROUTE_MOVE_RANDOM)
i = $game_variables[86]e = $game_map.eventsmove_route = RPG::MoveRoute.newmove_route.repeat = repeatmove_route.skippable = skippablemove_route.wait = waitmove_route.list = []move_route.list << RPG::MoveCommand.new(Game_Character::ROUTE_TURN_TOWARD)move_route.list << RPG::MoveCommand.new(Game_Character::ROUTE_END)e.force_move_route(move_route)you can add as many commands as you need, like this:
Code:
move_route.list << RPG::MoveCommand.new(Game_Character::ROUTE_MOVE_RANDOM)


That doesn't work. I'm not even sure if that is what I'm looking for. :/

Think event commands, but translated into Ruby. I'm trying to have an event turn toward a player and then wait x frames.
e = $game_map.eventsmove_route = RPG::MoveRoute.newmove_route.repeat = truemove_route.skippable = falsemove_route.wait = falsemove_route.list = []move_route.list << RPG::MoveCommand.new(Game_Character::ROUTE_TURN_TOWARD)move_route.list << RPG::MoveCommand.new(Game_Character::ROUTE_WAIT, [30])move_route.list << RPG::MoveCommand.new(Game_Character::ROUTE_END)e.force_move_route(move_route)this script should work.Why exactly are you doing this through scripts, though?
e = $game_map.eventsmove_route = RPG::MoveRoute.newmove_route.repeat = truemove_route.skippable = falsemove_route.wait = falsemove_route.list = []move_route.list << RPG::MoveCommand.new(Game_Character::ROUTE_TURN_TOWARD)move_route.list << RPG::MoveCommand.new(Game_Character::ROUTE_WAIT, [30])move_route.list << RPG::MoveCommand.new(Game_Character::ROUTE_END)e.force_move_route(move_route)this script should work.Why exactly are you doing this through scripts, though?


Oh wait, I got it to work (sorta). Thank you.

Now I need to figure out why my script takes like seconds and seconds of time to check all 216 events on the map.

The code basically does:

- Checks to see if the event exists

- Checks to see if the event is not "erased" by seeing if it is marked as "through"

- Checks to see if the event is named something specific (This step doesn't work so is subbed as a if true statement)

- Checks to see if the character is within 2 units of a specific event

- If the the character is within 2 units of a specific event then the event faces the character and both the character and event cannot move

- A message shows up in the in game message window and a battle starts

- The event is erased afterward and the character can move again

So on the map if I stand within 2 units of an event it takes like 7 seconds for it to realize I'm there. If I move back away after being within 2 units of an event it does not run as if I am there within 2 units after 7 seconds. My frames per second is barely affected by this script it seems.

By any chance, does this make my code work slow?

if $game_map.events[$game_variables[86]]For seeing if an event exists.
On the events, set an Autonomous Move Route as Custom, with the following:

Code:
Move Route: Script: turn_toward_player if (@x - $game_player.x).abs <= 2 and (@y - $game_player.y).abs <= 2
On the events, set an Autonomous Move Route as Custom, with the following:

Move Route: Script: turn_toward_player if (@x - $game_player.x).abs <= 2 and (@y - $game_player.y).abs <= 2
Err...thats not it. However that gives me an idea.

I realized that event I was running the code in is too slow for what I was trying. Even if I tired messing with it to speed up its too heavy for the game to run normally.
Ah, sorry - I misread. You want them to turn towards the player if they're within 2 tiles, wait 2 seconds, then turn to face their original direction?


How are you determining which events will do this? Your original code looked at a variable for the event id, then got the event from that variable. That's probably slow, because I'm assuming you're updating that variable within a loop somewhere.


Can you show us the full code that controls everything that's done?
Ah, sorry - I misread. You want them to turn towards the player if they're within 2 tiles, wait 2 seconds, then turn to face their original direction?

How are you determining which events will do this? Your original code looked at a variable for the event id, then got the event from that variable. That's probably slow, because I'm assuming you're updating that variable within a loop somewhere.

Can you show us the full code that controls everything that's done?
It won't work to begin with the same way I was trying.

What I wanted really is that a event will "play" when you get close to it within 2 tiles. In this case it would play a battle process.

Update: If I can get a switch to turn on through move route on the editor with that formula you gave me (except it turns on a switch), I can have a process auto-run the content I wanted to run.

2nd Update: Ok got it working almost, so close. Now I need a way to assign the ID number of the event setting the switch to true so I don't have to put it in manually.

$game_variables = @id if (@x - $game_player.x).abs <= 2 and (@y - $game_player.y).abs <= 2This however does not work. :/

3rd Update: @id does work, forgot to change a variable. Thank you it works now! 😀

4th Update: Just in case curious...I realized there was something wrong with the setup again and tweaked it a bit so that a self switch will go off and an auto-run page would be switched to from the first page in the same event. The second page contains what I wanted to be "played". This will prevent other events near by in range from changing battles wrongly, deleting events wrongly, and showing animations or balloons wrongly.

Original thread: https://forums.rpgmakerweb.com/threads/rpg-moveroute.42560/