Creating a Move Route via Script Call

Hello, as you may have seen in other threads here, I'm attempting to create an event where the map rotates on the press of a button. My newest thread went strangely silent, so I'm starting on a new facet of the event here.

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 |event|
$game_map.events[1].force_move_route(mr)
end

This section of code is meant to command all events on the map to rotate 90 degrees right, as to maintain correct perspective during the rotation. I received the original code from a tutorial on this process, here. (https://forums.rpgmakerweb.com/index.php?threads/creating-a-move-route-with-a-script-command.59367/) However, it does not function, and throws an error.

Game_Bug_004.png


Any help with this issue would be appreciated.
Code:
$game_map.events.each do |event|
event.force_move_route(mr)
end

event.force_move_route
event is the index you use to grab an event from events[]

if there's only one event currently on the map, it'll be event[0] which would be event itself at the loop of the iterator, and you're grabbing event[1] which doesn't exist.
With that change, it still crashes, just with a more interesting error.

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 |event|
event.force_move_route(mr)
end

Here's the error. If I'm simply being dumb, let me know; I'm terrible with code.

Game_Bug_005.png


If I set the code as "event[0].force_move_route(mr)", I get:

Game_Bug_006.png
.
A suggestion:
Follow the link "how to use a script" in my signature to the part about bughunting and the backtracer.
Install thenbacktracer to get better error messages, they might help pointing you to the cause of the problem.
You don't start a new thread to ask the same question just because the last one went quiet. You wait the appropriate time, and then you bump it. This now just means you have the same conversation happening in two places, which is going to cause extra work for the people who do view or respond to it, and more work for the mods.

You do not use $game_map.events[x] when you've already done $game_map.events.each. Your original code was running for each event on the map, but each time, it was applying the move route to event 1. Your second code (event[0]) is trying to apply the move route to event 0 each time. If you don't know code, just follow what is being suggested rather than making it up as you go.

Can you confirm that you actually ARE using VX Ace and not VX or XP? It's nowhere in your profile, and nowhere in your first post, so we're all just assuming it's Ace.
Shaz, the quiet one is on a related topic, but not the same one as this; I'm also well aware of bumping. Really, you could've just checked the other thread, it's only a few down from this one...

As far as I'm aware, using event[0] means you're referring to the event being ran, and event[-1] refers to the player, with all others being normal event ids. I had used event[1] by mistake, but I had thought that even with $game_map.events.each, you needed to be specific. If I'm not supposed to place that line, how should I refer to mr?

Edit: Yes, it's VX Ace. I really should have stated that; I usually do.

Thank you for the tip, Andar. This looks useful.
You're assuming I was looking at the RGSSx Script Support forum. I wasn't - I was looking at new posts. Your other thread was nowhere to be seen.

As far as event[0] being the event running, and event[-1] being the player, no. Game_Interpreter.character(0) refers to the current event, and Game_Interpreter.character(-1) refers to the player. $game_map.events is an array of events, where the index is the event id, so $game_map.events[0] is null, and EV001 is $game_map.events[1], and there is no way to refer to the player using $game_map.events because the player is not an event.

$game_map.events.each do |evt| will loop through all events on the map, and with each iteration, the event will be put into the variable evt. So if you have events 1, 2, and 3, on the first iteration, evt will be $game_map.events[1], on the second iteration, evt will be $game_map.events[2], and on the third iteration, evt will be $game_map.events[3]. So you just use evt to reference the event, and don't need to refer to $game_map.events again at all within the loop.

I don't know why you got the 'force move route invalid for #Array' error message - I can only think that you had $game_map.events.force_move_route in there rather than event.force_move_route.
Ah, sorry for the misunderstanding. My other thread was focusing on Z-levels in Parallax mapping, which is tied into the rotation event discussed here.

Ah, I see. I hadn't realized the difference. I'm still learning Ruby, so it's good to know there's both to choose from when needed.
My code at the bottom is now:

$game_map.events.each do |evt|
mr
end
.

Obviously, this does nothing in game, because I'm not sure how to tell these events to do "mr". I can tell it to

$game_map.events.each do |evt|
force_move_route(mr)
end
, as per your code, but then I get this NoMethodError.

Game_Bug_007.png


And in case you didn't see the edit I made: this is VX Ace, yes. I normally state that, but it seems I forgot this time.
make sure you don't call the script before $map.setup_events runs
setup_events makes @events be an array of game_events, instead of numbers.

for that, make sure you put the iterator block inside an interactive event., with a script command.

I can confirm you that the modification works, because I used it, without knowledge of the tutorial.... I came up with it on my own, and it's part of the cinematic system I use, so yes, it DOES work.
you're just coding it wrong somehow.
You can only activate this script in-game, so I assume we're safe?

(I have no idea.)

(Making it more complex doesn't help either. 😛)
the thing is a modification of the Force Move command, from the interpreter.
it affects events, which are only loaded when the map is loaded, which only happens in game.
so, yes, you need to trigger it from the game.
I never found an easy explanation to put commands to make an events moveroute.
The Scriptequivalent Thread Helped, but iam not sure if the answer is missing there or if i was to lagging of brainpower some time (years) ago.

Its possible but i dont know how to write down the commands to do so. Its the curse of us non scripters. MAybe someone figured it out in detail and is willing to share it in detail? 🙂

Edit: Your Last Thread was about turning maps, so i asume having an extra thread for event moveroute is a good thing, who would expect this to be in a map rotation thread.
Better one thread for every main problem in this case. atleast in my opinion.
We're getting a little sidetracked.

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 |evt|
force_move_route(mr)

Game_Bug_007.png


Any idea what's wrong here?
$game_map.events.each do |evt|
force_move_route(mr)

$game_map.events.each do |evt|
evt.force_move_route(mr)
end
The 'end' was already there, it just doesn't show in the Quote box for some reason. Now we get a rather strange error.

Game_Bug_008.png
just realized that @events is a hash.
from $game_map
Code:
def refresh
>>@events.each_value {|event| event.refresh }
  @common_events.each {|event| event.refresh }
  refresh_tile_events
  @need_refresh = false
end

each_value is a hash method.

try
Code:
$game_map.events.each_value {|evt|
evt.force_move_route(mr)
}

I forgot it was a hash.
I rigged my code to respond to get_character("name") and return a specific event by name, so I wouldn't have to work with the hash itself.
d'oh.
Excellent, it works in the test project. All that's left is to figure out how to make an exception for this, just in case, but that can wait until it's actually necessary, I suppose.

I tested it in my main project, and it works, though there's a single event spazzing out turning to the right and back over and over. Also, said event is one that has no need to turn. I guess we're not done, haha.
Please show a screenshot of your event, and if the script isn't entirely visible, copy/paste that here as well. In the screenshot, include the whole event window, not just the list of commands. What is the id (number) of the event that is spazzing out? Does it already have an autonomous move route and the two could be conflicting? Does it have an event page with a parallel process trigger that has a move route?

Obviously, this does nothing in game, because I'm not sure how to tell these events to do "mr". I can tell it to

Code:
$game_map.events.each do |evt|
force_move_route(mr)
end

, as per your code, but then I get this NoMethodError.

That is not as per my code. But you've already discovered that. I just want to highlight the importance of getting things right - you've been given instructions several times, and have then typed something different into your game.

just realized that @events is a hash

Oops - will have to go and check my tutorial! It works in my game, so there must be something different between what I did and what I posted.
Luckily, I put together an image of the entire rotation event recently. The event we've been using obviously has not been updated in the image, but it's up to date, aside from that.

Spoiler: Long Image
Code_9.png

The event spazzing out is a lantern the player can pick up to shine light, using Zeus81's Lights and Shadows script (https://forums.rpgmakerweb.com/index.php?threads/zeus-lights-shadows.16040/). I have confirmed that copying and pasting the event (thus making the id of the new event different) results in both events spazzing.

Code_10.png


When I say spazzing, I mean it goes from facing left, to facing right, instead of up. If I turn stepping animation off, it rotates up once properly, though I don't want this event to turn at all.

If I type something different into my game, I'm almost certainly trying to follow the given directions, but am unsure how. There's no reason for me to ignore help given, as I do not know how to do things such as this entirely by myself, yet.

Also, when I said "as per your code", I was referring to "force_move_route(mr)", which came from your tutorial. Sorry for any confusion.
It works in my game, so there must be something different between what I did and what I posted.
Code:
$game_map.events.each do |event|
 event[1].force_move_route(route)
end
event[1].force_move_route(route)
at the "this is an array" error, forcing it to pick 1 out of [key,value] solves the error, and might have lead into that $game_map.events[1] error of before.

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