• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • 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.

[Question] (Pokemon Essentials) How do I change the player's name to a variable?

  • 2
    Posts
    349
    Days
    Hi! I'm still very new to rpg maker xp and pokemon essentials but I've been picking up a few more things on coding events and I've been having trouble with one specific thing. There's a character that I want the player to be able to name in the intro that I want the player to be able to play as for a brief section. I know you store the names of npcs as variables however I'm not quite sure how you could call the variable in regards to changing the name of the protagonist with either $Trainer.Name (which I haven't been able to get working) or pbTrainerName("X") (I'm aware this script is destructive but it's right at the start of the game so I don't think it will be an issue).

    Basically

    How do I call a player-inputted text variable to change the protagonist's name to?
     

    Swdfm

    Game Developer
  • 245
    Posts
    5
    Years
    • he/him
    • UK
    • Seen Dec 8, 2023
    I presume you're using an older version of essentials, but this is still possible on there:
    Instead of changing the name, it would help to have it change based on variables.
    So, what we need to do is go into where the name is stored in the Trainer class
    It is stored in class PokeBattle_Trainer in your version, or class Player < Trainer in more modern version of Essentials.
    So, anywhere you wish, (either in a page past the trainer pages, and before Main, or in a Plugin), put:
    Code:
    YOUR_ALTERNATE_NAME = 69 # Not the actual name, but rather the variable number attached to the name
    
    def pbIsAlternateCharacter?
      # Change this to match the conditions that make the player this other character
      return true
    end
    
    
    class PokeBattle_Trainer
      def name
        if self == $Trainer # Stops it from affecting all NPCs. You DON'T need this line in more modern essentialls versions
          return pbGet(YOUR_ALTERNATE_NAME) if pbIsAlternateCharacter?
        end
        return @name
      end
    end

    However, this doesn't solve everything. there may be other problems that crop up as a result of changing only the name of the trainer. Everything else will be the same (Trainer type, pokemon party money etc.) Another suggestion is to create an entirely new Trainer object and save the old player using something like this)
    Code:
    ORIGINAL_PLAYER = 420
    def pbChangeToAlternateCharacter
      new_trainer = PokeBattle_Trainer.new(pbGet(YOUR_ALTERNATE_NAME), PBTrainers::TRAINER_TYPE)) # Ensure you change TRAINER_TYPE to the trainer type of your proposed alternative character
      # Saves the original trainer into a variable
      pbSet(ORIGINAL_PLAYER, $Trainer.clone)
      $Trainer = new_trainer 
    end
    To get the original trainer back:
    Code:
    def pbChangeFromAlternateCharacter
      new_trainer = $Trainer.clone
      $Trainer = pbGet(ORIGINAL_PLAYER)
      # If you don't wish to save the alternate character, remove this below line
      pbSet(ORIGINAL_PLAYER, new_trainer)
    end

    Hope this helps!
    Swdfm
     
    Back
    Top