• Just a reminder that providing specifics on, sharing links to, or naming websites where ROMs can be accessed is against the rules. If your post has any of this information it will be removed.
  • Our friends from the Johto Times are hosting a favorite Pokémon poll - and we'd love for you to participate! Click here for information on how to vote for your favorites!
  • Serena, Kris, Dawn, Red - which Pokémon protagonist is your favorite? Let us know by voting in our grand final favorite protagonist poll!
  • PokéCommunity supports the Stop Killing Games movement. If you're a resident of the UK or EU, consider signing one of the petitions to stop publishers from destroying games. Click here for more information!
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

Switch party position

  • 32
    Posts
    5
    Years
    • Seen yesterday
    Code:
    def pbSwitch
      
      for pokemon in $Trainer.party
        $Trainer.party[6]=$Trainer.party[0]
        $Trainer.party[0]=$Trainer.party[1]
        $Trainer.party[1]=$Trainer.party[2]
        $Trainer.party[2]=$Trainer.party[3]
        $Trainer.party[3]=$Trainer.party[4]
        $Trainer.party[4]=$Trainer.party[5]
        $Trainer.party[5]=$Trainer.party[6]
    end
    end
     

    Attachments

    • [PokeCommunity.com] Switch party position
      party switch.png
      26.9 KB · Views: 145
    • [PokeCommunity.com] Switch party position
      sqi.png
      26.9 KB · Views: 121
    I don't think you need the for loop? Also you probably shouldn't assign to $Trainer.party[6], but maybe it works fine? I'd have probably written the first and last lines like this:
    Code:
    tmp=$Trainer.party[0]
    ...
    $Trainer.party[5]=tmp

    when i start an battle make error "The party have 6 or more pokemon" i try to fix
     
    Your code wouldn't really work the way it's supposed to. You're not only duplicating the first Pokémon in the array (in the seventh slot), but you're also evaluating your code 5 times too many (which means 35 redundant assignment calls).

    Ruby has a few useful methods that make all this very simple.
    Array#pop: Deletes the last item of an array, and returns it.
    Array#insert: Places the given item at the given index within the array.

    Given this, we can pop the last Pokémon out of the array, and add it back in at the start of the array. That would simply be:
    Code:
    def pbSwitch
      $Trainer.party.insert(0, $Trainer.party.pop)
    end
     
    Last edited:
    Your code wouldn't really work the way it's supposed to. You're not only duplicating the first Pokémon in the array (in the seventh slot), but you're also evaluating your code 5 times too many (which means 35 redundant assignment calls).

    Ruby has a few useful methods that make all this very simple.
    Array#pop: Deletes the last item of an array, and returns it.
    Array#insert: Places the given item at the given index within the array.

    Given this, we can pop the last Pokémon out of the array, and add it back in at the start of the array. That would simply be:
    Code:
    def pbSwitch
      $Trainer.party.insert(0, $Trainer.party.pop)
    end

    thanks, i think make a input to do the script works
     
    Also, mej71 did a script if you press X or Z, will switch pokémons o.o just use what they did, tho.
     
    Back
    Top