[Ace] Iterating through an Event's Pages and updating content

Hello,

This may be a bit of a strange one, though I think it could be useful in certain situations. I have downloaded and am experimenting with Yanfly's Spawn Event script. This works great, except for certain entries in the spawned Event's Pages. Any command entered into the Event's Pages via the editor that uses 'This Event' to set the target will cause problems.

For example, I have an Event of a confused and startled girl that is summoned, and will go through a 'panic' move route. This Event is Event #2 on the map it resides within. Spawning the Event will cause a copy of the Event, with a new ID, to appear on the map. Interacting with the spawned Event will then cause Event #2 ON THIS MAP to animate!

So, given the new ID of the spawned Event, I'd attempt to (pseucode):

for each of the Event's Pages inspect each element. If it's a command that can potentially refer to an Event ID If the Event ID referred to is the ID number of the Event on its original map Replace the ID value with the new ID of the spawned event end if end ifend for In my example given above, I'd replace all Event ID references that = 2 to the new ID.

So how would I iterate across an Event's Pages, and for each Page iterate across each command?
# iterate each page in the eventevent.pages.each do |page| # iterate each command on the page page.list.each do |cmd| # something with the command endendThis script updates event commands because the new events are copied from existing events and so the ID's need to be updatedhttp://himeworks.wordpress.com/2013/03/17/connected-maps/

Go to line 137
Got it going now, APART from correctly updating the set self-switch command. That's not a huge deal, but for completion's sake do you have any ideas?

Here's what I got right now (showing relevant snippets only):

#==============================================================================# ¦ Event#==============================================================================module RPG class Event def update_for_new_id(val) @pages.each {|page| update_page_events(page, val) } end def update_page_events(page, val) page.list.each {|cmd| case cmd.code when 111 # cond branch, character (0, 1, 2, ...) cmd.parameters[1] = val if cmd.parameters[0] == 6 && cmd.parameters[1] > 0 when 122 # variables, character (0, 1 2, ... ) cmd.parameters[5] = val if cmd.parameters[4] == 5 && cmd.parameters[5] > 0 when 203 # set event location cmd.parameters[0] = val if cmd.parameters[0] > 0 cmd.parameters[2] = val if cmd.parameters[1] == 2 && cmd.parameters[2] > 0 when 205, 212, 213 # move route, animation, and balloon cmd.parameters[0] = val if cmd.parameters[0] > 0 end } end endend#==============================================================================# ¦ Game_Event#==============================================================================class Game_Event < Game_Character def update_for_new_id(val) @event.update_for_new_id(val) endendThe tricky thing here I think is that command 123 (set Self-Switch) params are just for which Self Switch (param[0]) and what value (param[1]) - no mention of the event id!

Original thread: https://forums.rpgmakerweb.com/threads/ace-iterating-through-an-events-pages-and-updating-content.16853/