• 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.

[Scripting Question] Sending an item to the Item Storage

72
Posts
5
Years
    • Seen Jan 24, 2021
    The item storage in the Trainer's PC. I'm trying to send an item directly to that storage. I've been looking at "pbStoreItem" and the method that places a Potion in the PC, but haven't had any success. Does anyone know how to do this? Any help is well appreciated.
     
    1,403
    Posts
    10
    Years
    • Seen Apr 29, 2024
    I mean it sounds like pbStoreItem should work. What have you tried, and what did it do?
     
    72
    Posts
    5
    Years
    • Seen Jan 24, 2021
    pbStoreItem seems to send an item to your Bag discreetly.
    I've seen pbStoreItem in mainly two places, which are both located in PItem_Bag.
    I use $PokemonBag.pbStoreItem(:item,quantity) to call it.

    Code:
      def initialize
        @items = []
        # Start storage with a Potion
        if hasConst?(PBItems,:POTION)
          pbStoreItem(getConst(PBItems,:POTION))
        end
      end
    I've tried to modify these, because it's the same code that sends a Potion to your PC at the beginning of game. I can't call it on command.



    Code:
      def pbStoreItem(item,qty=1)
        if item.is_a?(String) || item.is_a?(Symbol)
          item = getID(PBItems,item)
        end
        if !item || item<1
          raise ArgumentError.new(_INTL("Item number {1} is invalid.",item))
          return false
        end
        pocket = pbGetPocket(item)
        maxsize = maxPocketSize(pocket)
        maxsize = @pockets[pocket].length+1 if maxsize<0
        return ItemStorageHelper.pbStoreItem(@pockets[pocket],maxsize,BAGMAXPERSLOT,item,qty,true)
      end
    This seems to be what's storing items into the Bag. It's not what I want, but it works, so I've been looking at it too.
     
    1,403
    Posts
    10
    Years
    • Seen Apr 29, 2024
    pbStoreItem seems to send an item to your Bag discreetly.
    I've seen pbStoreItem in mainly two places, which are both located in PItem_Bag.
    I use $PokemonBag.pbStoreItem(:item,quantity) to call it.

    Code:
      def initialize
        @items = []
        # Start storage with a Potion
        if hasConst?(PBItems,:POTION)
          pbStoreItem(getConst(PBItems,:POTION))
        end
      end
    I've tried to modify these, because it's the same code that sends a Potion to your PC at the beginning of game. I can't call it on command.



    Code:
      def pbStoreItem(item,qty=1)
        if item.is_a?(String) || item.is_a?(Symbol)
          item = getID(PBItems,item)
        end
        if !item || item<1
          raise ArgumentError.new(_INTL("Item number {1} is invalid.",item))
          return false
        end
        pocket = pbGetPocket(item)
        maxsize = maxPocketSize(pocket)
        maxsize = @pockets[pocket].length+1 if maxsize<0
        return ItemStorageHelper.pbStoreItem(@pockets[pocket],maxsize,BAGMAXPERSLOT,item,qty,true)
      end
    This seems to be what's storing items into the Bag. It's not what I want, but it works, so I've been looking at it too.

    So I think you're basically on the correct track, you just needed to find out what the name of the global variable that stores an instance of this PCItemStorage class is. And I believe it's called "$PokemonGlobal.pcItemStorage".

    Although I should probably warn you that everywhere it's used it looks like this (take a look in PScreen_Bag for example):

    Code:
        if !$PokemonGlobal.pcItemStorage
          $PokemonGlobal.pcItemStorage = PCItemStorage.new
        end

    Which is a bit weird, because $PokemonBag is set once globally in PSystem_Utilities. I kinda think that it would make sense to move all the initialization of the PC there too, but maybe there's a reason why not to do that.

    Anyways, I haven't tested, but I would experiment with "$PokemonGlobal.pcItemStorage.pbStoreItem" if I were you.
     

    Ego13

    hollow_ego
    311
    Posts
    6
    Years
  • Do you want to automatically send an item to the storage under certain circumstance or do you want the player to choose an item?
     
    72
    Posts
    5
    Years
    • Seen Jan 24, 2021
    I've experimented with "$PokemonGlobal.pcItemStorage.pbStoreItem" as much as I could, but I haven't gotten any thing to work. it returns "undefined method" errors.
     
    1,403
    Posts
    10
    Years
    • Seen Apr 29, 2024
    I've experimented with "$PokemonGlobal.pcItemStorage.pbStoreItem" as much as I could, but I haven't gotten any thing to work. it returns "undefined method" errors.

    Did you try "new"ing the pcItemStorage like I showed above? I would expect that undefined method is happening because at this point in the game the player hasn't caused pcItemStorage to be initialized and so it's nil.

    But it could be something else. Hard to know without error messages.
     
    72
    Posts
    5
    Years
    • Seen Jan 24, 2021
    PHP:
    Interpreter:276:in `pbExecuteScript'
    Interpreter:1606:in `command_355'
    Interpreter:494:in `execute_command'
    Interpreter:193:in `update'
    Interpreter:106:in `loop'
    Interpreter:198:in `update'
    Scene_Map:163:in `update'
    Scene_Map:161:in `loop'
    Scene_Map:170:in `update'
    Scene_Map:234:in `main'
    [Pok?mon Essentials version 17.2]
    Exception: RuntimeError
    Message: Script error within event 18 (coords 5,7), map 2 (Lappet Town):
    Exception: TypeError
    Message: Intl_Messages:568:in `[]'Symbol as array index
    ***Full script:
    pbTrainerPC
    
    Interpreter:243:in `pbExecuteScript'
    Intl_Messages:568:in `get'
    Intl_Messages:683:in `get'
    Intl_Messages:720:in `pbGetMessage'
    PBItems:531:in `getName'
    PScreen_Mart:38:in `getDisplayName'
    PScreen_ItemStorage:36:in `drawItem'
    SpriteWindow_text:2086:in `refresh'
    SpriteWindow_text:2082:in `each'
    SpriteWindow_text:2082:in `refresh'
    
    Interpreter:276:in `pbExecuteScript'
    Interpreter:1606:in `command_355'
    Interpreter:494:in `execute_command'
    Interpreter:193:in `update'
    Interpreter:106:in `loop'
    Interpreter:198:in `update'
    Scene_Map:163:in `update'
    Scene_Map:161:in `loop'
    Scene_Map:170:in `update'
    Scene_Map:234:in `main'


    Yes, I think your right about what was causing the undefined methods. So I started opening the Item Storage beforehand. When I activate the event "$PokemonGlobal.pcItemStorage.pbStoreItem", nothing happens. But now when I check the Item Storage in the PC to see if the items made it, it returns the error above.
     
    72
    Posts
    5
    Years
    • Seen Jan 24, 2021
    I'm trying to send a item to the Storage, without any need of input from the Player. So sending an item to the PC under certain conditions sounds about right.
     
    1,403
    Posts
    10
    Years
    • Seen Apr 29, 2024
    PHP:
    Interpreter:276:in `pbExecuteScript'
    Interpreter:1606:in `command_355'
    Interpreter:494:in `execute_command'
    Interpreter:193:in `update'
    Interpreter:106:in `loop'
    Interpreter:198:in `update'
    Scene_Map:163:in `update'
    Scene_Map:161:in `loop'
    Scene_Map:170:in `update'
    Scene_Map:234:in `main'
    [Pok?mon Essentials version 17.2]
    Exception: RuntimeError
    Message: Script error within event 18 (coords 5,7), map 2 (Lappet Town):
    Exception: TypeError
    Message: Intl_Messages:568:in `[]'Symbol as array index
    ***Full script:
    pbTrainerPC
    
    Interpreter:243:in `pbExecuteScript'
    Intl_Messages:568:in `get'
    Intl_Messages:683:in `get'
    Intl_Messages:720:in `pbGetMessage'
    PBItems:531:in `getName'
    PScreen_Mart:38:in `getDisplayName'
    PScreen_ItemStorage:36:in `drawItem'
    SpriteWindow_text:2086:in `refresh'
    SpriteWindow_text:2082:in `each'
    SpriteWindow_text:2082:in `refresh'
    
    Interpreter:276:in `pbExecuteScript'
    Interpreter:1606:in `command_355'
    Interpreter:494:in `execute_command'
    Interpreter:193:in `update'
    Interpreter:106:in `loop'
    Interpreter:198:in `update'
    Scene_Map:163:in `update'
    Scene_Map:161:in `loop'
    Scene_Map:170:in `update'
    Scene_Map:234:in `main'


    Yes, I think your right about what was causing the undefined methods. So I started opening the Item Storage beforehand. When I activate the event "$PokemonGlobal.pcItemStorage.pbStoreItem", nothing happens. But now when I check the Item Storage in the PC to see if the items made it, it returns the error above.

    Code:
    PBItems:531:in `getName'

    So PBItems is code that gets generated at runtime. My guess is that the item you're giving is broken in such a way that trying to get its name causes the game to crash. Have you tried giving a plain old Potion or something? (More specifically, what are you trying to give, how have you defined it, and how are you calling pbStoreItem?)
     
    72
    Posts
    5
    Years
    • Seen Jan 24, 2021
    I've tried calling it in an event. I've use a Conditional Branch because using the script function breaks the code.

    PHP:
    Conditional Branch: Script: $PokemonGlobal.pcItemStorage.pbStoreItem(:POTION,2)
               @>
               Branch End

    I've also tried calling it in a script in two ways:

    PHP:
    pbAddNewItem

    Code:
    def pbAddNewItem
      if !$PokemonGlobal.pcItemStorage
      $PokemonGlobal.pcItemStorage = PCItemStorage.new
      end
      $PokemonGlobal.pcItemStorage.pbStoreItem(:POTION,2)
    end



    PHP:
    pbAddNewItem(:POTION,2)

    Code:
    def pbAddNewItem
      if !$PokemonGlobal.pcItemStorage
      $PokemonGlobal.pcItemStorage = PCItemStorage.new
      end
      $PokemonGlobal.pcItemStorage.pbStoreItem(:item,qty)
    end

    The first script returns the same error message above when I open the Storage.
    The second script returns an Argument Error.

    PHP:
    Interpreter:276:in `pbExecuteScript'
    Interpreter:1606:in `command_355'
    Interpreter:494:in `execute_command'
    Interpreter:193:in `update'
    Interpreter:106:in `loop'
    Interpreter:198:in `update'
    Scene_Map:163:in `update'
    Scene_Map:161:in `loop'
    Scene_Map:170:in `update'
    Scene_Map:234:in `main'
    [Pok?mon Essentials version 17.2]
    Exception: RuntimeError
    Message: Script error within event 10 (coords 12,7), map 2 (Lappet Town):
    Exception: ArgumentError
    Message: (eval):1:in `pbAddNewItem'wrong number of arguments(2 for 0)
    ***Full script:
    pbAddNewItem(:POTION,2)
    
    Interpreter:243:in `pbExecuteScript'
    (eval):1:in `pbExecuteScript'
    Interpreter:1606:in `eval'
    Interpreter:243:in `pbExecuteScript'
    Interpreter:1606:in `command_355'
    Interpreter:494:in `execute_command'
    Interpreter:193:in `update'
    Interpreter:106:in `loop'
    Interpreter:198:in `update'
    Scene_Map:163:in `update'


    I have only ever used Potions when trying to do this.
     
    72
    Posts
    5
    Years
    • Seen Jan 24, 2021
    I've only ever used Potions for this.

    I've been calling $PokemonGlobal.pcItemStorage.pbStoreItem(:POTION,2) in a conditional branch.
     
    72
    Posts
    5
    Years
    • Seen Jan 24, 2021
    I've tried calling it in an event. I've use a Conditional Branch because using the script function breaks the code.

    PHP:
    Conditional Branch: Script: $PokemonGlobal.pcItemStorage.pbStoreItem(:POTION,2)
               @>
               Branch End

    I've also tried calling it in a script in two ways:

    PHP:
    pbAddNewItem

    Code:
    def pbAddNewItem
      if !$PokemonGlobal.pcItemStorage
      $PokemonGlobal.pcItemStorage = PCItemStorage.new
      end
      $PokemonGlobal.pcItemStorage.pbStoreItem(:POTION,2)
    end



    PHP:
    pbAddNewItem(:POTION,2)

    Code:
    def pbAddNewItem
      if !$PokemonGlobal.pcItemStorage
      $PokemonGlobal.pcItemStorage = PCItemStorage.new
      end
      $PokemonGlobal.pcItemStorage.pbStoreItem(:item,qty)
    end

    The first script returns the same error message above when I open the Storage.
    The second script returns an Argument Error.

    PHP:
    Interpreter:276:in `pbExecuteScript'
    Interpreter:1606:in `command_355'
    Interpreter:494:in `execute_command'
    Interpreter:193:in `update'
    Interpreter:106:in `loop'
    Interpreter:198:in `update'
    Scene_Map:163:in `update'
    Scene_Map:161:in `loop'
    Scene_Map:170:in `update'
    Scene_Map:234:in `main'
    [Pok?mon Essentials version 17.2]
    Exception: RuntimeError
    Message: Script error within event 10 (coords 12,7), map 2 (Lappet Town):
    Exception: ArgumentError
    Message: (eval):1:in `pbAddNewItem'wrong number of arguments(2 for 0)
    ***Full script:
    pbAddNewItem(:POTION,2)
    
    Interpreter:243:in `pbExecuteScript'
    (eval):1:in `pbExecuteScript'
    Interpreter:1606:in `eval'
    Interpreter:243:in `pbExecuteScript'
    Interpreter:1606:in `command_355'
    Interpreter:494:in `execute_command'
    Interpreter:193:in `update'
    Interpreter:106:in `loop'
    Interpreter:198:in `update'
    Scene_Map:163:in `update'


    I have only ever used Potions when trying to do this.
     
    1,403
    Posts
    10
    Years
    • Seen Apr 29, 2024
    I've only ever used Potions for this.

    I've been calling $PokemonGlobal.pcItemStorage.pbStoreItem(:POTION,2) in a conditional branch.

    I think you want "$PokemonGlobal.pcItemStorage.pbStoreItem(getConst(PBItems, :POTION),2)", that seemed to work for me, and is similar to how the original Potion is stored in your PC.

    I am unsure why pbStoreItem doesn't check that you're not trying to stick a symbol in there (I guess this is why you get the error about using a symbol as an array index), or automatically convert that into the item. I think most methods work this way.
     
    Last edited:
    72
    Posts
    5
    Years
    • Seen Jan 24, 2021
    Oh! That completely works! It was really that simple? Thank you so much! This is greatly appreciated!
     
    Back
    Top