• 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.
  • Ever thought it'd be cool to have your art, writing, or challenge runs featured on PokéCommunity? Click here for info - we'd love to spotlight your work!
  • Which Pokémon Masters protagonist do you like most? Let us know by casting a vote in our Masters favorite protagonist poll here!
  • Red, Hilda, Paxton, or Kellyn - which Pokémon protagonist is your favorite? Let us know by voting in our poll!
  • 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.

[Scripting Question] Variables in scripts

  • 57
    Posts
    5
    Years
    • Seen Apr 17, 2022
    I need help with this script, I have made it using the codes already included in the Essentials.
    The problem comes from the part of pbprueba1. I can't get the variable to change, I can't even get it to work, I get an error.
    Because it does not work?
    The idea is that you change the variables depending on the choice.
    If someone could help me I would appreciate it.
    Code:
    class PokemonTransporte_Scene
        def shouldShow?
        return true
      end
      
      def pbprueba1
      $game_variables.SetVariables(45,1)
    end
    end
    
      def pbTransporteMenu
      loop do
        command=Kernel.pbMessage(_INTL("What do you want to do?"),[
           _INTL("Item Storage"),
           _INTL("Item Storage2"),
           _INTL("Exit")
           ],-1)
        if command==0
          pbprueba1
        elsif command==1
          pbPCMailbox
        else
          break
        end
      end
    end
     
    Have you tried with
    Code:
    yourVar == yourValue
    ?
     
    Try using
    Code:
    $game_variables[45] = 1
    without spaces other than the ones I've written
     
    Last edited:
    Try using
    Code:
    $game_variables[45] = 1
    without any kind of space or anything

    [PokeCommunity.com] Variables in scripts

    https://ibb.co/Z6CpWhY
    No, mistake again. I think I have linked an image of the error.
     
    What if you define pbTransporteMenu inside of the class?
     
    I don't think it is:
    Code:
    class PokemonTransporte_Scene
        def shouldShow?
        return true
      end
      
      def pbprueba1
      $game_variables.SetVariables(45,1)
    end
    end #this end here actually ends the class code
     
    Last edited:
    I don't think it is:
    Code:
    class PokemonTransporte_Scene
        def shouldShow?
        return true
      end
      
      def pbprueba1
      $game_variables.SetVariables(45,1)
    end
    end #this end here actually ends the class definition

    Code:
    class PokemonTransporte_Scene
        def shouldShow?
        return true
      end
      
      def pbTransporteMenu
      loop do
        command=Kernel.pbMessage(_INTL("What do you want to do?"),[
           _INTL("Item Storage"),
           _INTL("Item Storage2"),
           _INTL("Exit")
           ],-1)
        if command==0
          pbprueba1
        elsif command==1
          pbPCMailbox
        else
          break
        end
      end
    end
    
      def pbprueba1
      $game_variables[45] = 1
    end
    end

    Thus? It is the first time that I work with class in this way
     
    Give it a try
     
    No, now the menu, Item Storage, Item Storage2 doesn't even appear. I think that is not how it is defined. o There is some end too many.
     
    Hmm. What I could recommend you is trying to call a common event using pbCommonEvent(id of the common event) then showing the menu from there or replacing
    Code:
    loop do
      #...
    end
    with
    Code:
    while (true)
      #...
    end
    With the first method, you'd have a fix for the issue with changing a variable from the script section
     
    Hmm. What I could recommend you is trying to call a common event using pbCommonEvent(id of the common event) then showing the menu from there or replacing
    Code:
    loop do
      #...
    end
    with
    Code:
    while (true)
      #...
    end
    With the first method, you'd have a fix for the issue with changing a variable from the script section

    I could swear but I don't know if it's what I'm looking for. I want to make the player get a menu to choose a destination, and depending on the variable they teleport to one place or another, a way to avoid the Flight MO in the game, and in a more interesting way than an item.
     
    Then you should try the first method. In that way, teleporting the player would be very easy as RPG Maker XP and I believe all other RPG Makers have a built-in "Teleport to map" function
     
    Then you should try the first method. In that way, teleporting the player would be very easy as RPG Maker XP and I believe all other RPG Makers have a built-in "Teleport to map" function

    Thanks for the idea, but I want to do it from the variables and for an NPC to be the one to execute the teleportation, because it is simpler to change the player's appearance to a sprite that varies in a sequence until it is teleported. That's the idea, but if I can't do it, I'll have to learn to program it, I guess.

    Thanks anyway. I hope you can help me, although you have already done a lot to try to help me. Thanks again.
     
    Sorry, I think I didn't explain well. You could make the NPC call a common event in which you set the variable (or if you need to make the variable change value before the common event, then change it from the NPC's event) and show the choice. You would still be able to boot the game's PC from a script function.

    I'm suggesting to use a common event as it would be easier for it to be called by different NPCs.
     
    Sorry, I think I didn't explain well. You could make the NPC call a common event in which you set the variable (or if you need to make the variable change value before the common event, then change it from the NPC's event) and show the choice. You would still be able to boot the game's PC from a script function.

    I'm suggesting to use a common event as it would be easier for it to be called by different NPCs.

    Ok, I got it, but the problem is that now I can only use three selections and it will be crazy for the player when they have to move through the cities through this method.
     
    This (click on the word "this" to go to the page) is what you're looking for. Pokémon Essentials introduces the ability to add tons of options for a choice, a feature that RPG Maker doesn't have.
     
    Back
    Top