[SOLVED] Fix for Dynamic Party Positions Script

😂EDIT:
This post has been solved. I'll leave the final, fixed version of the script here if anyone wants to access it. I was provided with 2 solutions, and both work, so I'll also leave the 2nd solution in there, but commented (not active in the script).
Spoiler: Script Final Fix - Kylock's Dynamic Party Positions
Ruby:
#=============================================================================
# Kylock's Dynamic Party Positions for RPG Tankentai Sideview Battle System
# By Kylock
#=============================================================================
# This add-on by Kylock will dynamically change the positioning of
# party members in battle depending on the amount of party members that
# are fighting.  This script has no effect on anything else besides how
# actor sprites are positioned.
#
# To customize coordinates, read the comments in the middle of this script.
#
# The ACTOR_POSITION array and MAX_MEMBERS value in the SBS Configurations
# script are overwritten by this script.
#
# Positions will not be dynamic when used in Battle Test.
#
# *Installation:
#   This script add-on should be placed below the Sideview scripts in the
# script editor.  KGC_LargeParty should be placed BELOW this add-on if you are
# using that script.
#
# *Script comments added by Mr. Bubble.
#=============================================================================

module N01
  MAX_BATTLE_MEMBERS = 4    # Max battle members in a party.  This value is
                            # overwritten by KGC_LargeParty.
end

class Game_Party < Game_Unit
  #--------------------------------------------------------------------------
  # * Constants
  #--------------------------------------------------------------------------
  MAX_MEMBERS = N01::MAX_BATTLE_MEMBERS       # Maximum number of party members
  def add_actor(actor_id)
    if @actors.size < MAX_MEMBERS and not @actors.include?(actor_id)
      @actors.push(actor_id)
      $game_player.refresh
      update_formation
    end
  end
  def setup_starting_members
    @actors = []
    for i in $data_system.party_members
      @actors.push(i)
    end
    update_formation
  end
  def remove_actor(actor_id)
    @actors.delete(actor_id)
    $game_player.refresh
    update_formation
  end
  def update_formation
    case @actors.size
  # This section is where you define your member coordinates.
  # The coordinate set that is used depends on the amount of actors battling.
  # Settings for up to 5 members are already pre-defined, but more can be added.
  # These coordinates are not used in Battle Test. See bottom of script for info.
    when 1: $ACTOR_POSITION = [[415,185],[0,0],[0,0],[0,0]]
    when 2: $ACTOR_POSITION = [[395,155],[435,215],[0,0],[0,0]]
    when 3: $ACTOR_POSITION = [[385,140],[415,185],[445,230],[0,0]]
    when 4: $ACTOR_POSITION = [[385,140],[405,170],[425,200],[445,230]]
    end
  end
end

module N01

 #--------------------------------------------------------------------------
 # ● Settings
 #--------------------------------------------------------------------------
  # Actor starting posistions
  #                   X   Y     X   Y     X   Y     X   Y
  #$ACTOR_POSITION = [[440,200],[480,160],[455,200],[505,220],[480,260]]
  # Maximum party members that can fight at the same time.
  # Remember to add to the ACTOR_POSITION array to accomodate.
  MAX_MEMBER = N01::MAX_BATTLE_MEMBERS
end

class Game_Actor < Game_Battler
  def base_position    # Actor positions for Battle Test only.
    $ACTOR_POSITION = [[430,140],[480,160],[455,200],[505,220],[480,260]] if $BTEST
    $game_party.update_formation
    base = $ACTOR_POSITION[self.index]
    @base_position_x = base[0]
    @base_position_y = base[1]
    # バックアタック時はX軸を逆に
    @base_position_x = Graphics.width - base[0] if $back_attack && N01::BACK_ATTACK
  end
end

#Alternative
=begin
class Scene_File
 
  alias_method(:write_save_data_ILC_beforeActorPosition, :write_save_data)
  def write_save_data(file)
    write_save_data_ILC_beforeActorPosition(file)
    Marshal.dump($ACTOR_POSITION, file)
  end
 
  alias_method(:read_save_data_ILC_beforeActorPosition, :read_save_data)
  def read_save_data(file)
    read_save_data_ILC_beforeActorPosition(file)
    $ACTOR_POSITION = Marshal.load(file)
  end
end
=end



ORIGINAL POST:

Hello all!

I hope you're doing fine today. I wanted to see if anyone could take a quick look at Kylock's Dynamic Party Positions Script for Tankentai Sideview Battle System (VX).

This script allows us to customize the positioning of party members in battle according to how many party members we currently have, which helps use the space on the screen in a way that looks better.

Spoiler: Without Dynamic Party Positions
Script WITHOUT.jpg
Spoiler: With Dynamic Party Positions
Script WITH.jpg

Problem:
The script works perfectly while playing. However, once you save, exit the game (closing completely the game window), then reopen and load up your saved game, the following error screen pops up as soon as you enter another battle:

Spoiler: Error Message
ERROR.jpg

That would be the only problem. Otherwise, the script works perfectly all the time. If anyone could dedicate a few mins to see what could be causing the error, I'd deeply appreciate it.

Spoiler: Script
Ruby:
#=============================================================================
# Kylock's Dynamic Party Positions for RPG Tankentai Sideview Battle System
# By Kylock
#=============================================================================
# This add-on by Kylock will dynamically change the positioning of
# party members in battle depending on the amount of party members that
# are fighting.  This script has no effect on anything else besides how
# actor sprites are positioned.
#
# To customize coordinates, read the comments in the middle of this script.
#
# The ACTOR_POSITION array and MAX_MEMBERS value in the SBS Configurations
# script are overwritten by this script.
#
# Positions will not be dynamic when used in Battle Test.
#
# *Installation:
#   This script add-on should be placed below the Sideview scripts in the
# script editor.  KGC_LargeParty should be placed BELOW this add-on if you are
# using that script.
#
# *Script comments added by Mr. Bubble.
#=============================================================================

module N01
  MAX_BATTLE_MEMBERS = 4    # Max battle members in a party.  This value is
                            # overwritten by KGC_LargeParty.
end

class Game_Party < Game_Unit
  #--------------------------------------------------------------------------
  # * Constants
  #--------------------------------------------------------------------------
  MAX_MEMBERS = N01::MAX_BATTLE_MEMBERS       # Maximum number of party members
  def add_actor(actor_id)
    if @actors.size < MAX_MEMBERS and not @actors.include?(actor_id)
      @actors.push(actor_id)
      $game_player.refresh
      update_formation
    end
  end
  def setup_starting_members
    @actors = []
    for i in $data_system.party_members
      @actors.push(i)
    end
    update_formation
  end
  def remove_actor(actor_id)
    @actors.delete(actor_id)
    $game_player.refresh
    update_formation
  end
  def update_formation
    case @actors.size
  # This section is where you define your member coordinates.
  # The coordinate set that is used depends on the amount of actors battling.
  # Settings for up to 5 members are already pre-defined, but more can be added.
  # These coordinates are not used in Battle Test. See bottom of script for info.
    when 1: $ACTOR_POSITION = [[415,185],[0,0],[0,0],[0,0]]
    when 2: $ACTOR_POSITION = [[395,155],[435,215],[0,0],[0,0]]
    when 3: $ACTOR_POSITION = [[385,140],[415,185],[445,230],[0,0]]
    when 4: $ACTOR_POSITION = [[385,140],[405,170],[425,200],[445,230]]
    end
  end
end

module N01
 #--------------------------------------------------------------------------
 # ● Settings
 #--------------------------------------------------------------------------
  # Actor starting posistions
  #                   X   Y     X   Y     X   Y     X   Y
  #$ACTOR_POSITION = [[440,200],[480,160],[455,200],[505,220],[480,260]]
  # Maximum party members that can fight at the same time.
  # Remember to add to the ACTOR_POSITION array to accomodate.
  MAX_MEMBER = N01::MAX_BATTLE_MEMBERS
end

class Game_Actor < Game_Battler
  def base_position    # Actor positions for Battle Test only.
    $ACTOR_POSITION = [[430,140],[480,160],[455,200],[505,220],[480,260]] if $BTEST
    base = $ACTOR_POSITION[self.index]
    @base_position_x = base[0]
    @base_position_y = base[1]
    # バックアタック時はX軸を逆に
    @base_position_x = Graphics.width - base[0] if $back_attack && N01::BACK_ATTACK
  end
end
Spoiler: Problem Section
Ruby:
class Game_Actor < Game_Battler
  def base_position    # Actor positions for Battle Test only.
    $ACTOR_POSITION = [[430,140],[480,160],[455,200],[505,220],[480,260]] if $BTEST
    base = $ACTOR_POSITION[self.index] #>>>>>>>>>THIS SEEMS TO BE THE PROBLEM
    @base_position_x = base[0]
    @base_position_y = base[1]
    # バックアタック時はX軸を逆に
    @base_position_x = Graphics.width - base[0] if $back_attack && N01::BACK_ATTACK
  end
end

This is a clean project with Tankentai SBS + Kylock's Dynamic Party Positions for testing.
Spoiler: Demo

Thanks for reading, and thanks in advance for any help!
The problem is that the array is only available while testing the battle system. It has to be enabled, well, always. That means you need to remove the if conditional statement there.
Ahá! That certainly takes care of the error screen! However, if I do that, the script then completely ignores the previously set dynamic positions:
Ruby:
 when 1: $ACTOR_POSITION = [[415,185],[0,0],[0,0],[0,0]]
 when 2: $ACTOR_POSITION = [[395,155],[435,215],[0,0],[0,0]]
 when 3: $ACTOR_POSITION = [[385,140],[415,185],[445,230],[0,0]]
 when 4: $ACTOR_POSITION = [[385,140],[405,170],[425,200],[445,230]]
and I get stuck again with this one positioning setup in every scenario:
Ruby:
$ACTOR_POSITION = [[430,140],[480,160],[455,200],[505,220],[480,260]] if $BTEST
😮😮😮
Been playing around with the code for a bit, but haven't found an answer yet...
The actor positions don't seem to be stored with the save data and get lost when the game is closed.
If you don't touch the $ACTOR_POSITION array otherwise you could try to add
$game_party.update_formation
to the beginning of the problematic method to setup the array with your current actor formation instead.

Alternatively you could make the game store/restore the actor position data with your save data:
Spoiler
Ruby:
class Scene_File
 
  alias_method(:write_save_data_ILC_beforeActorPosition, :write_save_data)
  def write_save_data(file)
    write_save_data_ILC_beforeActorPosition(file)
    Marshal.dump($ACTOR_POSITION, file)
  end
 
  alias_method(:read_save_data_ILC_beforeActorPosition, :read_save_data)
  def read_save_data(file)
    read_save_data_ILC_beforeActorPosition(file)
    $ACTOR_POSITION = Marshal.load(file)
  end
end
Well, calling it dynamic might be an overstatement here...

Ruby:
module N01
 #--------------------------------------------------------------------------
 # ● Settings
 #--------------------------------------------------------------------------
  # Actor starting posistions
  #                   X   Y     X   Y     X   Y     X   Y
  #$ACTOR_POSITION = [[440,200],[480,160],[455,200],[505,220],[480,260]]
  # Maximum party members that can fight at the same time.
  # Remember to add to the ACTOR_POSITION array to accomodate.
  MAX_MEMBER = N01::MAX_BATTLE_MEMBERS
end

You commented out that $ACTOR_POSITION line of code, right?

EDIT

Based on Another Fen's suggestion, saving the data in a game file seems quite unnecessary here.
It's way easier to configure that variable inside that N01 module OR do what Fen said about calling $game_party.update_formation before battle begins.
$game_party.update_formation
This worked! I've been testing it for a bit in different scenarios, and it seems to have done the job! 😀
The alternative method also worked! :LZScheeze:

I really gotta thank you for your interest and support, guys! I was really bummed that this script was not working to be honest. @Another Fen thanks again, really really appreciate this, 2nd time in a row you save me, haha :mrsatan: @kyonides thank you as well for all your support. You have some pretty awesome scripts btw, I've been browsing 😀

I'll leave the final fixed version of the script in the original post in case anyone wants to access it.

This issue has been solved. This post can be closed now. Thanks!

Original thread: https://forums.rpgmakerweb.com/threads/solved-fix-for-dynamic-party-positions-script.161570/