Lead Actor Swapper script error
#21
0. In Ruby Ruby indexes start at 0, not 1.

1. Yes, that internal value will get replaced automatically. Sad

2. It looks for anybody in that specific position. The script doesn't know or care about previous swaps. Happy with a sweat

3. So everybody hates Basil now!? Laughing

Here's the updated script! Grinning
Please read the embedded comments. Winking They're worth it!

Code:
# * Kuick Leader Swap XP * #
#   Scripter : Kyonides
#   v1.0.0 - 2025-09-06

# * Script Calls * #

# - Set a Temporary Leader!
#  RememberLeaderIndex? stands for a boolean value: true or false.
#  This new leader becomes permanent if RememberLeaderIndex? is false.
# $game_party.temp_leader(PartyIndex, RememberLeaderIndex?)

# - Restore the Previous Leader! (If Any!)
# $game_party.restore_leader

# - Set a Leader by Actor's ID!
# $game_party.set_leader_by_id(ActorID)

class Game_Party
  def change_leader(n)
    if n < 0
      @actors.unshift @actors.pop
    else
      @actors << @actors.shift
    end
  end

  def set_leader_by_id(actor_id)
    n = @actors.index(actor_id)
    swap_leader(n) if n
  end

  def temp_leader(n, remember)
    @temp_leader_index = n if remember
    swap_leader(n)
  end

  def restore_leader
    return unless @temp_leader_index
    n = @temp_leader_index
    swap_leader(@temp_leader_index)
    @temp_leader_index = nil
  end

  def leader
    @actors[0]
  end
  private
  def swap_leader(n)
    @actors[0], @actors[n] = @actors[n], @actors[0]
    $game_player.refresh
  end
end

class Game_Player
  alias :kyon_kuick_leader_swap_gm_plyr_up :update
  def update
    kyon_kuick_leader_swap_gm_plyr_up
    if Input.trigger?(Input::L)
      $game_party.change_leader(-1)
      refresh
      return
    elsif Input.trigger?(Input::R)
      $game_party.change_leader(1)
      refresh
    end
  end
end
"For God has not destined us for wrath, but for obtaining salvation through our Lord Jesus Christ," 1 Thessalonians 5:9

Maranatha!

The Internet might be either your friend or enemy. It just depends on whether or not she has a bad hair day.

[Image: SP1-Scripter.png]
[Image: SP1-Writer.png]
[Image: SP1-Poet.png]
[Image: SP1-PixelArtist.png]
[Image: SP1-Reporter.png]

My Original Stories (available in English and Spanish)

List of Compiled Binary Executables I have published...
HiddenChest & Roole

Give me a free copy of your completed game if you include at least 3 of my scripts! Laughing + Tongue sticking out

Just some scripts I've already published on the board...
KyoGemBoost XP VX & ACE, RandomEnkounters XP, KSkillShop XP, Kolloseum States XP, KEvents XP, KScenario XP & Gosu, KyoPrizeShop XP Mangostan, Kuests XP, KyoDiscounts XP VX, ACE & MV, KChest XP VX & ACE 2016, KTelePort XP, KSkillMax XP & VX & ACE, Gem Roulette XP VX & VX Ace, KRespawnPoint XP, VX & VX Ace, GiveAway XP VX & ACE, Klearance XP VX & ACE, KUnits XP VX, ACE & Gosu 2017, KLevel XP, KRumors XP & ACE, KMonsterPals XP VX & ACE, KStatsRefill XP VX & ACE, KLotto XP VX & ACE, KItemDesc XP & VX, KPocket XP & VX, OpenChest XP VX & ACE
Reply
#22
0. Got it! I figured as much from previous custom scripts (and the behavior when I selected a value of 1)

1. OK!

2. This is perfect.  Laughing

3. I know, right? What did he ever do (I remember him as a peacemaker)  Laughing

4. I tested out the updated script, and tried this set-up for a test event: 

Code:
@> Conditional Branch: [Aluxes] is in the party
  @> Script: $game_party.set_leader_by_id(1)
  @>
 : Else
  @>
 : Branch End

But nothing seems to happen.  Confused I made sure Aluxes was in the party and that he wasn't the leader when I interacted with the test event.
[Image: SP1-Writer.png]
[Image: SP1-PixelArtist.png]
Reply
#23
Oops! I forgot to include an important step, to pass the actor's ID to the $game_actors array before looking for his current position.
Happy with a sweat Stuff happens, you know.

Here's the fixed code!

Code:
# * Kuick Leader Swap XP * #
#  Scripter : Kyonides
#  v1.0.2 - 2025-09-06

# * Script Calls * #

# - Set a Temporary Leader!
#  RememberLeaderIndex? stands for a boolean value: true or false.
#  This new leader becomes permanent if RememberLeaderIndex? is false.
# $game_party.temp_leader(PartyIndex, RememberLeaderIndex?)

# - Restore the Previous Leader! (If Any!)
# $game_party.restore_leader

# - Set a Leader by Actor's ID!
# $game_party.set_leader_by_id(ActorID)

class Game_Party
  def change_leader(n)
    if n < 0
      @actors.unshift @actors.pop
    else
      @actors << @actors.shift
    end
  end

  def set_leader_by_id(actor_id)
    actor = $game_actors[actor_id]
    n = @actors.index(actor)
    swap_leader(n) if n and n != 0
  end

  def temp_leader(n, remember)
    @temp_leader_index = n if remember
    swap_leader(n)
  end

  def restore_leader
    return unless @temp_leader_index
    n = @temp_leader_index
    swap_leader(@temp_leader_index)
    @temp_leader_index = nil
  end

  def leader
    @actors[0]
  end
  private
  def swap_leader(n)
    @actors[0], @actors[n] = @actors[n], @actors[0]
    $game_player.refresh
  end
end

class Game_Player
  alias :kyon_kuick_leader_swap_gm_plyr_up :update
  def update
    kyon_kuick_leader_swap_gm_plyr_up
    if Input.trigger?(Input::L)
      $game_party.change_leader(-1)
      refresh
      return
    elsif Input.trigger?(Input::R)
      $game_party.change_leader(1)
      refresh
    end
  end
end
"For God has not destined us for wrath, but for obtaining salvation through our Lord Jesus Christ," 1 Thessalonians 5:9

Maranatha!

The Internet might be either your friend or enemy. It just depends on whether or not she has a bad hair day.

[Image: SP1-Scripter.png]
[Image: SP1-Writer.png]
[Image: SP1-Poet.png]
[Image: SP1-PixelArtist.png]
[Image: SP1-Reporter.png]

My Original Stories (available in English and Spanish)

List of Compiled Binary Executables I have published...
HiddenChest & Roole

Give me a free copy of your completed game if you include at least 3 of my scripts! Laughing + Tongue sticking out

Just some scripts I've already published on the board...
KyoGemBoost XP VX & ACE, RandomEnkounters XP, KSkillShop XP, Kolloseum States XP, KEvents XP, KScenario XP & Gosu, KyoPrizeShop XP Mangostan, Kuests XP, KyoDiscounts XP VX, ACE & MV, KChest XP VX & ACE 2016, KTelePort XP, KSkillMax XP & VX & ACE, Gem Roulette XP VX & VX Ace, KRespawnPoint XP, VX & VX Ace, GiveAway XP VX & ACE, Klearance XP VX & ACE, KUnits XP VX, ACE & Gosu 2017, KLevel XP, KRumors XP & ACE, KMonsterPals XP VX & ACE, KStatsRefill XP VX & ACE, KLotto XP VX & ACE, KItemDesc XP & VX, KPocket XP & VX, OpenChest XP VX & ACE
Reply
#24
(09-06-2025, 05:49 AM)Ace_V Wrote: Thank you so much for these two scripts!! I tried them both but Dervv's script seems to only move around the caterpillar and not the main character? (the three characters behind do swap around, but it duplicates the lead into the second, then into the third, and fourth, but the lead doesn't swap out for some reason.)

I'm puzzled.   It works just as its meant with no duplication of the lead actor.  Video attached. 

Couple that, it affects the entire party, and not just the caterpillar system.  For any caterpillar script, the party leading the caterpillar script must be the actual party leader, not some designated temp leader. So the party itself must reflect who is in the lead. The caterpillar system is completely dependent upon the party and its order.

You and kyonides seem to be in a more compatible set of time-zones, so I'll back away from the repair. However, if you have an issue with my script not functioning as above that there may also be something else in play.


Attached Files
.mp4   2025-09-06 08-28-16_Segment_0_x264.mp4 (Size: 1,019.85 KB / Downloads: 8)
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)

[Image: QrnbKlx.jpg]
[Image: sGz1ErF.png]    [Image: liM4ikn.png]    [Image: fdzKgZA.png]    [Image: sj0H81z.png]
[Image: QL7oRau.png]    [Image: uSqjY09.png]    [Image: GAA3qE9.png]    [Image: 2Hmnx1G.png]    [Image: BwtNdKw.png%5B]
  Above are clickable links
Reply
#25
(09-06-2025, 10:42 AM)kyonides Wrote: Oops! I forgot to include an important step, to pass the actor's ID to the $game_actors array before looking for his current position.
Happy with a sweat Stuff happens, you know.

Here's the fixed code!
Code:
--------------------------

This works perfectly now!! Also reorders the party in the menu and is really easy to implement the script call. I'm going to go through my older quests to swap characters around. Thank you so much, kyonides!


(09-06-2025, 01:37 PM)DerVVulfman Wrote:
(09-06-2025, 05:49 AM)Ace_V Wrote: Thank you so much for these two scripts!! I tried them both but Dervv's script seems to only move around the caterpillar and not the main character? (the three characters behind do swap around, but it duplicates the lead into the second, then into the third, and fourth, but the lead doesn't swap out for some reason.)

I'm puzzled.   It works just as its meant with no duplication of the lead actor.  Video attached. 

Couple that, it affects the entire party, and not just the caterpillar system.  For any caterpillar script, the party leading the caterpillar script must be the actual party leader, not some designated temp leader.  So the party itself must reflect who is in the lead.  The caterpillar system is completely dependent upon the party and its order.

You and kyonides seem to be in a more compatible set of time-zones, so I'll back away from the repair.  However,  if you have an issue with my script not functioning as above that there may also be something else in play.

It really is odd! I tested your script on a blank project that also contained my game's scripts.rxdata just now and it still duplicates the lead for some reason.  Indifferent (Though I was able to get Basil back by cycling a few more times until there was no more duplicate of Aluxes, haha)
I appreciate all the help with this request despite the time zone difference! It also gave me a reason to look over my game's various scripts and I began rediscovering what my 2005 self was tinkering with back then. (among other things, I had forgotten I implemented a janky regen script that involved changing some of the standard scripts instead of being a new entry in itself, and it changed the regen text color as well) The little break from graphics and event-work was also refreshing.


Attached Files Thumbnail(s)
   
[Image: SP1-Writer.png]
[Image: SP1-PixelArtist.png]
Reply
#26
(Yesterday, 04:46 AM)Ace_V Wrote: It really is odd! I tested your script on a blank project that also contained my game's scripts.rxdata just now and it still duplicates the lead for some reason.  Indifferent (Though I was able to get Basil back by cycling a few more times until there was no more duplicate of Aluxes, haha)

Its not a blank script if it contains your game's current scripts.rxdata.  A blank project with only those scripts that come default are the test, such as this:  
.zip   Project1ddd.zip (Size: 923.2 KB / Downloads: 6)

Otherwise, you may have other code that is itself interfering... rewrites or direct edits otherwise.  Content you may have forgotten.
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)

[Image: QrnbKlx.jpg]
[Image: sGz1ErF.png]    [Image: liM4ikn.png]    [Image: fdzKgZA.png]    [Image: sj0H81z.png]
[Image: QL7oRau.png]    [Image: uSqjY09.png]    [Image: GAA3qE9.png]    [Image: 2Hmnx1G.png]    [Image: BwtNdKw.png%5B]
  Above are clickable links
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
   Actor Voices by diamondandplatinum3, note-tag commands not working! Starmage 1 524 08-04-2025, 09:02 AM
Last Post: Starmage
   Plugin or Script help with Item menu, SKill menu, and Equip menu JayRay 3 2,799 11-22-2024, 07:02 PM
Last Post: JayRay
   Atoa ACBS, Equipment Set Add-on Error Solitaire 10 5,897 10-13-2024, 11:41 PM
Last Post: Solitaire
   Personal graph by actor zlsl 4 7,899 10-23-2021, 06:43 AM
Last Post: zlsl
   Script compatibility help Lord Vectra 3 7,113 07-25-2021, 11:42 PM
Last Post: DerVVulfman
   Adding face script on Cogwheel's RTAB Battle Status rekkatsu 15 22,383 08-25-2020, 03:09 AM
Last Post: DerVVulfman
   "Wait" in the script Whisper 13 21,683 04-28-2020, 04:06 PM
Last Post: Whisper
   Skill Cooldown script Fenriswolf 11 21,618 12-10-2019, 11:10 AM
Last Post: Fenriswolf
   (RMVXace) Battle error with Tankentai's battle system, help. x( Starmage 0 5,060 02-14-2018, 04:25 PM
Last Post: Starmage
   Help iwth script (RGSS Player crash) Whisper 3 10,489 06-17-2017, 05:03 PM
Last Post: Whisper



Users browsing this thread: 2 Guest(s)