XP Changing screen tone in battle without using battle events

I'm creating a battle where I want the screen to change color in a rainbow pattern constantly but with battle events it either would only happen once per turn and not during one too or prevent attacking entirely while it loops forever. I could have it change to a different color every turn, but I would rather have it always happening. Is there a way I could create a script that runs while a switch is on to do that without events? Additionally, I want it to only start happening after 2 turns have happened, if that would change anything.
Hey,

Generally if you want something to happen constantly during battle, you could tap into the "update" method of Scene_Battle. This method is run once every frame (Assuming you are using RPGMaker XP):

Ruby:
class Scene_Battle
 
  # Save the previous method version under a new name:
  alias_method(:update_without_rainbow_event, :update)
 
  # Replace the update method with a new one:
  def update
    # <Added Extra Stuff:>
    # If Switch 177 is on, try to run Common Event 166 on a loop in the background:
    if $game_switches[177]
      # - Create a new event interpreter the first time it is needed:
      if !@rainbow_interpreter
        @rainbow_interpreter = Interpreter.new
      end
      # - Load Common Event 166 if the interpreter never ran or reached the end:
      if !@rainbow_interpreter.running?
        @rainbow_interpreter.setup($data_common_events[166].list, 0)
      end
      # - Advance the loaded event by one frame:
      @rainbow_interpreter.update
    end
    # <End of Extra Stuff>
    # Old Update Process:
    update_without_rainbow_event
  end
end
You can of course also code in your stuff directly here.
Keep in mind that if you ever want to change gameplay related stuff in the background (like changing someones HP), the status- and menu windows may not immediately update without further modifications.
Hey,

Generally if you want something to happen constantly during battle, you could tap into the "update" method of Scene_Battle. This method is run once every frame (Assuming you are using RPGMaker XP):

Ruby:
class Scene_Battle
 
  # Save the previous method version under a new name:
  alias_method(:update_without_rainbow_event, :update)
 
  # Replace the update method with a new one:
  def update
    # <Added Extra Stuff:>
    # If Switch 177 is on, try to run Common Event 166 on a loop in the background:
    if $game_switches[177]
      # - Create a new event interpreter the first time it is needed:
      if !@rainbow_interpreter
        @rainbow_interpreter = Game_Interpreter.new
      end
      # - Load Common Event 166 if the interpreter never ran or reached the end:
      if !@rainbow_interpreter.running?
        @rainbow_interpreter.setup($data_common_events[166].list, 0)
      end
      # - Advance the loaded event by one frame:
      @rainbow_interpreter.update
    end
    # <End of Extra Stuff>
    # Old Update Process:
    update_without_rainbow_event
  end
end
You can of course also code in your stuff directly here.
Keep in mind that if you ever want to change gameplay related stuff in the background (like changing someones HP), the status- and menu windows may not immediately update without further modifications.
When I add that as a new script and the variable is turned on, it gives me an error.
Code:
Script 'The Figure's Rainbowizer' line 13: NameError occurred.

uninitialized constant Scene::Battle_Interpreter
I also changed the switch to 240 and the common event to 55.
Oh, woops. Don't have the Maker installed to test the code, forgot that in XP the class is called "Interpreter" instead of "Game_Interpreter".
Fixed that above.
Oh, woops. Don't have the Maker installed to test the code, forgot that in XP the class is called "Interpreter" instead of "Game_Interpreter".
Fixed that above.
Now it works.

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/changing-screen-tone-in-battle-without-using-battle-events.180144/