Creating a Move Route via Script Call

I've been toying around with the code on @Shaz 's tutorial, and I've finally made some progress.

mr = RPG::MoveRoute.new
mr.repeat = false
mr.wait = true
mr.list = []
mr.list.push( RPG::MoveCommand.new(36, []) )
mr.list.push( RPG::MoveCommand.new(20, []) )
mr.list.push( RPG::MoveCommand.new )
for evt in 1..4
$game_map.events[evt].force_move_route(mr)
end

for evt in 6..9
$game_map.events[evt].force_move_route(mr)
end

By using this code, all events from 1-9, except 5, the lantern that spazzes out, will turn, leaving the lantern untouched and functional. However, 9 is far too few events for this map, so I attempted to expand upon the number of events like so:

for evt in 10..20
$game_map.events[evt].force_move_route(mr)
end

It crashed with a NoMethodError. Eventually, I figured out that the number cannot exceed the number of events on your map. As this map is still in testing, there are only 11 events so far.
Thus:

mr = RPG::MoveRoute.new
mr.repeat = false
mr.wait = true
mr.list = []
mr.list.push( RPG::MoveCommand.new(36, []) )
mr.list.push( RPG::MoveCommand.new(20, []) )
mr.list.push( RPG::MoveCommand.new )
for evt in 1..4
$game_map.events[evt].force_move_route(mr)
end

for evt in 6..11
$game_map.events[evt].force_move_route(mr)
end

It works like a charm. I'm not sure what causes the spazzing in the first place, but this will band-aid the issue for now. I know it's not Stepping Animation, as I tested that. Thank you all for your help.
Why don't you just handle the exceptions for these events instead of telling the code exactly which ones to change?
Spoiler
Code:
mr = RPG::MoveRoute.new
mr.repeat = false
mr.wait = true
mr.list = []
mr.list.push( RPG::MoveCommand.new(36, []) )
mr.list.push( RPG::MoveCommand.new(20, []) )
mr.list.push( RPG::MoveCommand.new )

$game_map.events.each do |id,ev|
  next if [5].include?(id)
  ev.force_move_route(mr)
end
You see that next if line with the array? Enter the IDs of the events you don't want to trigger the force move route on into that array.
Simple syntax, more readable, and easily editable.
And just to note, this is how you iterate a hash if you need both the keys and values from it during the iteration.

Ohh, and I keep seeing code lines here without code tags.
Please, use code tags for your code lines to keep their format, otherwise my eyes will pop out. *.*
Thanks for the tip. This certainly seems a lot less annoying than what I've been using. I don't immediately understand how it would work, so I'll play with the code to see how it ticks.
Edit: Plug and play, nice!

Also, what's a code tag? And how do I use one?

Code:
mr = RPG::MoveRoute.new
mr.repeat = false
mr.wait = true
mr.list = []
mr.list.push( RPG::MoveCommand.new(36, []) )
mr.list.push( RPG::MoveCommand.new(20, []) )
mr.list.push( RPG::MoveCommand.new )

$game_map.events.each do |id,ev|
  next if [5].include?(id)
  ev.force_move_route(mr)
end
In the post editor, 8th button from the right, click on it.
You will see a drop-down menu. You can select spoiler and code tags there, for example.
Put your code lines in the code editor which pops up, or simply hit the Insert button to add the code tags and enter the code lines between the 2 code tags added to your post.
This will keep the format of your code lines and prevents the text from transforming into smileys.
It was the ninth button for me, but it works, thanks!

Original thread: https://forums.rpgmakerweb.com/threads/creating-a-move-route-via-script-call.87467/