[RMXP] Battlebacks

Started by Jaiden, November 14, 2017, 08:05:56 pm

Previous topic - Next topic

Jaiden

November 14, 2017, 08:05:56 pm Last Edit: November 20, 2017, 04:55:30 pm by BoisterousHero
All set on this now, but I'll leave it for future reference so someone else doesn't do what I did.

RPG Maker XP default battlebacks are not 640x480. If you use them with a transparent window, you won't notice the transparency! Took me hours to figure that one out, derp.





Jaiden

...I don't think I can use RPG Maker anymore.

...The status menu was not opaque because I was using a battleback that was not 640x480...

If anyone would like to help me figure out why the window dispose isn't working correctly after battle though, that would be helpful.

lilbrudder917

Wow, it's been a while since I've stopped lurking and actually made a post.

In "SBSXP BATTLE 1" you need to uncomment lines 139 and 143. The comments are preventing
@status_window.dispose

and
@result_window.dispose if @result_window != nil
from running, which keeps them from being disposed.

Jaiden

Quote from: lilbrudder917 on November 14, 2017, 10:26:52 pm
Wow, it's been a while since I've stopped lurking and actually made a post.

In "SBSXP BATTLE 1" you need to uncomment lines 139 and 143. The comments are preventing
@status_window.dispose

and
@result_window.dispose if @result_window != nil
from running, which keeps them from being disposed.


Bless you for even looking at this disaster. Thank you.

I didn't realize those were commented out, I think I thought it was already present in the windows_dispose method. It's definitely a step in the right direction.

lilbrudder917

Quote from: BoisterousHero on November 14, 2017, 10:41:01 pm

Bless you for even looking at this disaster. Thank you.

I didn't realize those were commented out, I think I thought it was already present in the windows_dispose method. It's definitely a step in the right direction.


You know that would make sense, right? I thought the same thing when I looked at it. I kept trying to move the order of certain things around. I tried setting line 1117 (@status_window.visible = true) to false, thinking that was just a mistake. Seems like windows_dispose comes up a few times for purposes other than ending the battle, so those two lines are really the only pieces that needed to be changed as far as I can tell.

Jaiden

November 14, 2017, 10:51:17 pm #5 Last Edit: November 14, 2017, 10:53:08 pm by BoisterousHero
QuoteI tried setting line 1117 (@status_window.visible = true) to false, thinking that was just a mistake

I did the same thing, which is why I was confused.  Assuming it was just for cleaning up, I added those windows to it, but I got a disposed windows error. Reviewing windows_dispose, it looks like it disposes...some windows...sometimes? This is the battle I'm currently having with this system, since everything is just all over the place.

Those two lines did resolve the problem, so that's one less problem. For now.

Now to figure out why making the @help_window visible on the escape attempt phase forces my actor to attack instead! :D :facepalm:

Jaiden

So I've come across what I believe to be the biggest logic disaster in this thing and that's with the main frame update.

I have two frame updates here, one that is aliased within the ATB script, and one that is utilized by my battle system (it's actually the RMXP default)

What jumped out at me is the ATB alias calls the original method in the middle of the script. How exactly does that work? Does it run the original method, then return back to the aliased method?

If that's the case, I see some conflicts with the phase processing, because if the update_phase# is called by the main update method before the aliased one, then the aliased one will not continue, correct?

Any thoughts on how I would restructure this to be compatible? Would I just call the original method at the end of the aliased one?

Main frame update:
Spoiler: ShowHide
 #---------------------------------------------------------------------------
  # * Main battle frame update
  #---------------------------------------------------------------------------
  def update
  # If battle event is running
    if $game_system.battle_interpreter.running?
      # Update interpreter
      $game_system.battle_interpreter.update
      # If a battler which is forcing actions doesn't exist
      if $game_temp.forcing_battler == nil
        # If battle event has finished running
        unless $game_system.battle_interpreter.running?
          # Rerun battle event set up if battle continues
          unless judge
            setup_battle_event
          end
        end
        # If not after battle phase
        if @phase != 5
          # Refresh status window
          @status_window.refresh
        end
      end
    end
    # Update system (timer) and screen
    $game_system.update
    $game_screen.update
    # If timer has reached 0
    if $game_system.timer_working and $game_system.timer == 0
      # Abort battle
      $game_temp.battle_abort = true
    end
    # Update windows
    @help_window.update
    @party_command_window.update
    @actor_command_window.update
    @active_battler_window.update
    @status_window.update
    @message_window.update
    # Update sprite set
    @spriteset.update
    # If transition is processing
    if $game_temp.transition_processing
      # Clear transition processing flag
      $game_temp.transition_processing = false
      # Execute transition
      if $game_temp.transition_name == ""
        Graphics.transition(20)
      else
        Graphics.transition(40, "Graphics/Transitions/" +
          $game_temp.transition_name)
      end
    end
    # If message window is showing
    if $game_temp.message_window_showing
      return
    end
    # If effect is showing
    if @spriteset.effect?
      return
    end
    # If game over
    if $game_temp.gameover
      # Switch to game over screen
      $scene = Scene_Gameover.new
      return
    end
    # If returning to title screen
    if $game_temp.to_title
      # Switch to title screen
      $scene = Scene_Title.new
      return
    end
    # If battle is aborted
    if $game_temp.battle_abort
      # Return to BGM used before battle started
      $game_system.bgm_play($game_temp.map_bgm)
      # Battle ends
      battle_end(1)
      return
    end
    # If waiting
    if @wait_count > 0
      # Decrease wait count
      @wait_count -= 1
      return
    end
    # If battler forcing an action doesn't exist,
    # and battle event is running
    if $game_temp.forcing_battler == nil and
       $game_system.battle_interpreter.running?
      return
    end
    # Branch according to phase
    case @phase
    when 1  # pre-battle phase
      update_phase1
    when 2  # party command phase
      update_phase2
    when 3  # actor command phase
      update_phase3
    when 4  # main phase
      update_phase4
    when 5  # after battle phase
      update_phase5
    end
  end


Aliased one:
Spoiler: ShowHide
Quote#--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  alias acbs_update_atb update
  def update
    #Update the battle phases
   if @phase == 1
      $game_temp.battle_main_phase = true
      @actor_command_window.opacity = 0
      @phase = 0
    elsif @phase != 5
      @phase = 0
    end
   #Check if an event is running
    @event_running = true if $game_system.battle_interpreter.running?
   
   #Check for game over
   return $scene = Scene_Gameover.new if $game_temp.gameover
   
   #Call the original method
   acbs_update_atb
   
   #...Check if an event is running again??
   if $game_system.battle_interpreter.running?
      return
    elsif @event_running
      @status_window.refresh
      @event_running = false
    end
   
   #Check if we're on the post-battle phase
   return update_phase5 if @phase == 5
   
   #??????EVENT RUNNING????????
   @event_running = true if $game_system.battle_interpreter.running?
    if @update_turn_end
      turn_ending
      @update_turn_end = false
    end
   
    #Update escape
   if Input.press?(Escape_Input) and @escape_type > 0
      if $game_temp.battle_can_escape
        $game_temp.max_escape_count = update_phase2_escape_rate
        $game_temp.escape_count += 2 unless @wait_on
        @escaping = true
        if !@help_window.visible and @escape_type == 1
          @help_window.set_text('')
          @help_window.set_text(Escape_Message, 1)
        end
        if @escape_type == 2
          if @escape_atb_meters.nil?
            @escape_atb_meters = Escape_Meters.new
            @escape_meter_opacity = 0
            @escape_atb_meters.visible = true
          else @escape_atb_meters != nil
            @escape_atb_meters.opacity = 15 * @escape_meter_opacity
            @escape_meter_opacity = [@escape_meter_opacity + 1, 17].min
            @escape_atb_meters.refresh
          end
        end
        if $game_temp.escape_count >= $game_temp.max_escape_count
          $game_temp.escape_count = 0
          update_phase2_escape unless $game_party.all_dead?
        end
      else
        @help_window.set_text(Cant_Escape_Message, 1) if @escape_type == 1       
        if @escape_type == 2       
          if @escape_atb_meters.nil?
            @escape_atb_meters = Escape_Meters.new
            @escape_meter_opacity = 0
            @escape_atb_meters.visible = true
          else @escape_atb_meters != nil
            @escape_atb_meters.opacity = 15 * @escape_meter_opacity
            @escape_meter_opacity = [@escape_meter_opacity + 1, 17].min
            @escape_atb_meters.refresh
          end
        end
      end
    elsif @escape_type > 0
      if @escaping
        @escaping = false
        @help_window.visible = false
      end
      $game_temp.escape_count = [$game_temp.escape_count - 1, 0].max unless @wait_on
      if @escape_atb_meters != nil and $game_temp.escape_count == 0
        @escape_atb_meters.opacity = 15 * @escape_meter_opacity
        @escape_meter_opacity = [@escape_meter_opacity - 1, 0].max
        if @escape_meter_opacity == 0
          @escape_atb_meters.dispose
          @escape_atb_meters = nil
        end
      end
      @escape_atb_meters.refresh if @escape_atb_meters != nil
    end
    #Exit method if escape was successful
   return if @escaped
   
   #Perform the basic ATB update
   atb_update
   
   #Update the battler input
    input_battler_update(false)
    if @action_battlers[0] != nil && @action_battler.nil?
      @action_battlers.flatten!
      @action_battler = @action_battlers[0]
      if @action_battler.dead?
        @action_battler.atb = 0
        @action_battler = nil
      else
        start_phase4
      end
    end
   
   #Update the action battler
    if @action_battler != nil && !@spriteset.effect?
      @active_battler = @action_battler
      update_phase4
    end
   
  end


Also, this aliased one looks like it's checking the interpreter like 10 times, can't quite understand why.

This is in reference the demo in my OP, if more context is needed.

KK20

A method stops running only if either
1) it reaches the end of its method, or
2) it returns something prior to reaching end

Calling an alias in the middle of a method is not unheard of at all. It's good if you want to make some checks prior to calling the original method and seeing if they changed afterwards.

What I don't understand is how @phase is updating. At the start of every update, it's being set to zero. I don't see anywhere in the original update method where it is adjusted back to 1 through 5, making me suspect that the author wants to call the original update method without calling the update_phaseX methods.

I can understand the reason for $game_system.battle_interpreter.running? after the alias call since we don't want to update the ATB while an event is running. The second call for it though doesn't make sense to me

   #??????EVENT RUNNING????????
   @event_running = true if $game_system.battle_interpreter.running?

It's impossible for @event_running to ever be set to true here since the method should have returned by now if an event is still running.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Jaiden

That helps a lot actually, thanks. That makes understanding the flow of things a little easier.

I'll have to re-evaluate how the phase system is being used, as I had a really hard time interpreting that too. There are two versions of this ATB script, one that's a bit updated (but not compatible with my base system) that I've been referring to for some logic changes/better comments, and I noticed that exact snippet of phase update code is in that one, too.