Cycle through party members

● ARCHIVED · READ-ONLY
Started by oldbone 6 posts View original ↗
  1. I'm not so good at arrays in ruby yet.

    Here's my ask:

    Script 1:

    - cycle through all party members

    - remove them from the party, but store their actor ID

    Script 2:

    - add back in each actor removed by script 1 (I'm assuming we need to store their actor ids in an array to read back in)

    That's all !

    Thanks!
  2. What do you mean by cycle? Iterating all the party members one by one?

    First all members can be obtained from this line : $game_party.members

    That will give you an array consist of all your party members.

    To iterate over array, there are many2 ways in ruby, what I often use is #each  <= method each

    you can do like this $game_party.members.each { |element| #do what you want with element }    <= element here is the object in the array in each element.

    the name is not mandatory element, it just a variable and you can change the name as your liking.

    For removing from the party I don't understand what you want, there's always Change Party Members in Event Command right?

    Or you want to mess it with script? Then you can use these methods,

    $game_party.add_actor(actor ID)  <= add new member

    $game_party.remove_actor(actor ID)  <= remove new member

    and yes you need the actor ID, so you want to store their ID first in a variable =)
  3. Yeah, for cycling through actors in the party, I use this:

          $game_party.all_members.each do |actor|        #my code here      end And I can remove each actor easily. 

    What I cannot do, is -later on- call another script to add the REMOVED MEMBERS only back into the party. 

    Sure, I can set aside a variable and store IDs for "removed actor 1" into var 1... and "removed actor 2" into var 2... and so on.

    But, isn't there a more elegant way to achieve this with an array? So, something like:

    SCRIPT 1:

          $game_party.all_members.each do |actor|        remove the actor store the removed actor's ID in an array      end SCRIPT 2:

          <for each item in my array>        add the stored array value actor id back into the party      end Thanks!

     

     
  4. Script 1 :

    array_id = []$game_party.members.each do |member| remove the actor array_id.push(#Removed actor ID) } # <= method #push is what you want.endThen array_id will be an array contains this  [removed actor id, removed actor id, removed actor id]  <= The size depends on how many actor you removed.

     But there's something that concern me, variable array_id is not global, by that means, it will dissapeared in the next script call(you know what I mean right?)

    Script 2 :

    And to add back your removed actor, you want to get the IDs, and if by any chance(by any chance) the variable array_id is still can be used, you can iterate it back to add the actor back to the party.

    array_id.each { |id| $game_party.add_actor(id) } # <= if I'm not wrong I hope I do it right.
  5. Thanks! That worked. I just made the array a game variable and I can reference it long after the fact. Here's what I used and thanks for helping me understand arrays!

    Script 1 (removing all but actor 1):

    $game_variables[999] = []$game_party.members.each do |actor|     a = actor.id   if a != 1 ; $game_party.remove_actor(a) ; end   $game_variables[999].push(a)    endScript 2:

    Code:
    $game_variables[999].each { |id| $game_party.add_actor(id) } 
  6. Uh..That's great if I actually made a help, though I believe I don't be a much of help.

    For your purpose I would consider to create a new custom method in Game_Interpreter class that will do all what it's need to do what you want(err how do I explain it?)  If you haven't do it.

    For instance :

    class Game_Interpreter  def oldbone_remove_actor( exception_id ) # <= Script 1 @temp_removed_id = [] $game_party.members.each do |actor|      id = actor.id next if id == exception_id  $game_party.remove_actor(id) @temp_removed_id.push(id) end end def oldbone_add_removed_actor # <= Script 2 return if @temp_removed_id.nil? || @temp_removed_id.empty? @temp_removed_id.each {|id| $game_party.add_actor(id) } endend # End of Game_Interpreter
    You just need to call a short script call for each Script you wanted and it would make your life easier =) (Also don't need damn variables :p )

    P.S : Again I don't test it, I'm not in situation where I can check if it function properly or not, you might want to tweak it a bit if error occured. But I hope that will inspire you.Sorry if I do it wrong XD