Advanced Help with my Move Route/conditional branch

Okay,


Now that Shaz has kindly gotten me to understand the basics of Move Route, I am finding that what I am doing is pretty inefficient and causing a few bugs. I am hoping someone could take a look at what I am doing here and help me out.


Within the event itself I have this script


if Input.press?🙂X) &&
$game_player.direction == 2 && $game_player.x == $game_map.events[3].x &&
$game_player.y == $game_map.events[3].y-1 or $game_player.direction == 4 &&
$game_player.x == $game_map.events[3].x+1 && $game_player.y == $game_map.events[2].y or
$game_player.direction == 6 && $game_player.x == $game_map.events[3].x-1 &&
$game_player.y == $game_map.events[3].y or $game_player.direction == 8 &&
$game_player.x == $game_map.events[3].x && $game_player.y == $game_map.events[2].y+1

$game_temp.reserve_common_event(3)

$game_map.events[3].force_move_route(@mr)

$game_map.events[3].force_move_route(@mr1)
end


Which is basically checking to see what direction the player is facing, if they are pushing X and if the enemy is in the x/y next to the player in that direction. It then is supposed to do this move route


@mr = RPG::MoveRoute.new
@mr.repeat = false
@mr.wait = true
@mr.skippable = true
@mr.list = []

@mr.list.push( RPG::MoveCommand.new(35, []) )
@mr.list.push( RPG::MoveCommand.new(29, [5]) )
@mr.list.push( RPG::MoveCommand.new(44, [RPG::SE.new('blow1'), 80, 100]) )
@mr.list.push( RPG::MoveCommand.new(32, []) )
@mr.list.push( RPG::MoveCommand.new(11, []) )
@mr.list.push( RPG::MoveCommand.new(29, [3]) )
@mr.list.push( RPG::MoveCommand.new )

@mr1 = RPG::MoveRoute.new
@mr1.repeat = false
@mr1.wait = true
@mr1.list = []

@mr1.list.push( RPG::MoveCommand.new(42, [100]) )
@mr1.list.push( RPG::MoveCommand.new(15, [3]) )
@mr1.list.push( RPG::MoveCommand.new(42, [255]) )
@mr1.list.push( RPG::MoveCommand.new(31, []) )
@mr1.list.push( RPG::MoveCommand.new(36, []) )
@mr1.list.push( RPG::MoveCommand.new )


Which I placed into a common event, as these steps will be used for every event like this and I figured that would save space. I get an error whenever I face the event, I do not even have to be pushing the X button.


list error.PNG


Any suggestions on what I am doing wrong, or how to make this process a little easier would be a great help.
Where are you creating the move routes?  You've got them listed below the condition/action script in your post, but they would need to be above it in the actual event - otherwise when you force a move route using @mr or @mr1, they don't exist, which is why you're getting the nilclass error.


Your condition is also faulty.  && and 'or' have the same precedence, and you have no brackets around it to show what tests have to be performed together.  This means the conditions you THINK it is looking for are not the conditions it is REALLY looking for, so sometimes it might activate when you don't expect it to, and sometimes it won't activate when you do expect it to.  You should put () around all the && checks.  However, there's a better way to determine if the event is on the tile that the player is facing.



Before I elaborate on that, I'm curious why you're trying to do this via script calls?  I'm not seeing anything in there that would cause it to require a script instead of just event commands.  So perhaps the first thing to do would be to explain why you're doing it via script calls rather than move routes (and what the move route commands are meant to do, as I'd have to open up Ace and look at the scripts to work out its purpose).  Unless I'm misunderstanding something, I would just make the event with an Action Button trigger, and add the move route.  That would do all the checking for 'player has pressed space and is on the tile next to the event and is facing the event'.
The () would be a good start, I didn't even think of that. I have the move routes in the common event, I was hoping that the call common event action would basically have the move route set when I made the force move happen.


The reason I am doing this in a script instead of a move route was to save time on all the conditional branches I would need to check the location of the player/event and also because the project I am working on is basically a way for me to learn and test out how things work with scripts vs using events.
mmm ... but having the event set to action button is all that's needed to do all those checks for player/event location.


Action button says "the player must be on the tile below me and facing up, or on the tile to the left of me and facing right, or on the tile to the right of me and facing left, or on the tile above me and facing down" - I think that's everything you've got in your conditional branches.  It also does the Input.press🙂X) test (which is what activates the event).  Is there something else those conditions are testing that can't be tested just with an Action Button trigger?  What IS the trigger on your event?


It's certainly a good way to tinker around with scripts, but if that's all the conditions are doing, it's not necessary and means doubling the work, since the event won't be activated unless all those conditions have been tested and met, and then you're testing them all again.
Well basically what I am trying for is a Zelda like action system. You strike the enemy, they take damage and get knocked back, if it doesn't kill them. I started using the script because I could not find a conditional branch trigger with events that checked for enemy location to be next to the player. Is there a simpler way to accomplish this?
An event with an Action Button trigger will only run if the event is next to the player.  I asked you what is the trigger for your event, but you haven't answered that yet.


Perhaps you should post the entire event so we can see the context.
Sorry didn't catch that, I am making it a parallel process, so it is always running but will only trigger once you meet the requirements. This is the event so far:


event 1.PNG


Just keep in mind this is only a sample so I can test what I have as I go, so it is not complete.
That's inefficient and will cause lag.  Unless you have something that you WANT to happen every frame, just change it to Action Button and get rid of all those conditional branches.  Then you can use a regular move route and the problem will be solved.
I considered that angle, the problem I run into at that point is the attack of the enemy. I am making the enemies attack when they are in certain X and Y vs the player, so if I make it trigger on action button, I am unsure how to proceed with the enemy's attack as well.
ah, gotcha.


I'm sure there are other people who have made battle 'systems' like this, just through eventing.  I wonder if you might find something in the VX Ace tutorials forum, or with a search for 'on map battle system' or something like that (that will come up with a few scripts as results, but I'm sure I've seen people who are doing it with events)
That is a great idea. I usually try to make my own things 'original' but that seems foolish when I'm doing things I have no skill with lol. I will check out some of these others and see if I can get some ideas or see how it was done. Thanks again Shaz.

Original thread: https://forums.rpgmakerweb.com/threads/advanced-help-with-my-move-route-conditional-branch.59410/