Galv Item Storage/Bank Bug

I'm currently using Galv's Item Storage script, and have run into an issue. To make a long story short, my main programmer and I need to make the 'store_rem' script call to remove an item from storage. Using this script call, however, appears to just wipe the storage box entirely. We've attempted this both with other scripts installed, and just the one script on its own, and we just keep getting the same result.

Can anyone help us figure out what the issue is?
do you use: "store_rem(type, id, amount)" or using: store_rem(amount).
can you show a screenshot of the event?

you could or might miss something, so you can double check if you
have the demo or miss something in the script (if you need to edit it).
do you use: "store_rem(type, id, amount)" or using: store_rem(amount).
can you show a screenshot of the event?

you could or might miss something, so you can double check if you
have the demo or miss something in the script (if you need to edit it).
Using "store_rem(type, id, amount)".

Here's a screenshot:

1664638010478.png


We're using Galv's script in tandem with Raizen's Lune Grid Inventory, as well as a few custom scripts I commissioned from my programmer, but they've already told me that they tested it without any other scripts and ran into the same problem.
we just keep getting the same result.
Do you have the variable set for the storage box BOX_VAR?
Are you changing it at any time?

I'm testing this on the galv demo and it's working fine for me. but how are you testing it on the galv demo?
1664643180880.png


And the taken_from_storage must be a part of your custom scripts.
Do you have the variable set for the storage box BOX_VAR?
Are you changing it at any time?

I'm testing this on the galv demo and it's working fine for me. but how are you testing it on the galv demo?
View attachment 241743

And the taken_from_storage must be a part of your custom scripts.

I have BOX_VAR set to 0, since it's going to be just one universal storage for the whole game. The taken_from_storage is from one of the custom scripts, yeah. I'll ask my programmer how they're testing it, but they said they tested it without any other scripts, so I'm not totally sure what could have gone wrong.
Moved to: RGSSx Script Support
Thank you Shaz!

So, an update, spoke to my programmer, turns out I got it wrong, the only scripts they tested it without were the custom ones I commissioned from them. All other scripts I had installed were left untouched by them. So, that was my bad for misunderstanding.

I then spent the day plugging each script from my project into the Demo project that Galv includes with the item storage script, and they all seemed to work fine there, so I decided instead to turn my attention to my own project. I've commented out every single script under Materials aside from Galv's item storage one, and yet still the store_rem call deletes everything in storage.

I am at a complete loss as to what the issue is. I initially thought it was because I had edited something in the engine's base scripts, but I scanned through all of those and the only things I noticed out of place were some menu commands I had commented out, namely for things like the equip menu, status menu, formation menu, etc. And un-commenting them didn't seem to fix the issue either, so I'm officially back to square one.
If you want to load your project up for someone to take a look at, you could create a new map with one event that adds items to storage to set things up, and another that uses your script call to remove the item. Just to make it super easy for someone to reproduce the problem without having to spend a long time stumbling about trying to figure out what to do. Then put it on dropbox and post the link (or PM someone - if you do it in the next half hour I could take a look)

Okay, got it ...

With your demo project, it worked fine if I bought multiples of an item - when I trashed one, it would just trash one. But when I only had one of each item, and I trashed one, it wiped out everything, just as you said.

For some reason Galv has this:
Code:
  def multi_storage_set(item, amount)
    type = mstore_type(item)
    @storage[$game_variables[Storage::BOX_VAR]][type][item.id] ||= 0
    @storage[$game_variables[Storage::BOX_VAR]][type][item.id] = amount
    
    if @storage[$game_variables[Storage::BOX_VAR]][type][item.id] <= 0
      @storage[$game_variables[Storage::BOX_VAR]][type].delete_if { |key,value|
        key >= 0 # <<<<<<<<<<<<<<<<<<<<<
      }
    end
  end

which means as soon as you call multi_storage_set (which you do with store_rem), if it removes all of one item, it will delete every item where the key is 0 or greater.

I suspect it should be this instead:
Code:
  def multi_storage_set(item, amount)
    type = mstore_type(item)
    @storage[$game_variables[Storage::BOX_VAR]][type][item.id] ||= 0
    @storage[$game_variables[Storage::BOX_VAR]][type][item.id] = amount
    
    if @storage[$game_variables[Storage::BOX_VAR]][type][item.id] <= 0
      @storage[$game_variables[Storage::BOX_VAR]][type].delete_if { |key,value|
        value <= 0 # <<<<<<<<<<<<<<<<<<<<<<<<<<<
      }
    end
  end

So change line 875 and it should work fine.
Code:
value <= 0
If you want to load your project up for someone to take a look at, you could create a new map with one event that adds items to storage to set things up, and another that uses your script call to remove the item. Just to make it super easy for someone to reproduce the problem without having to spend a long time stumbling about trying to figure out what to do. Then put it on dropbox and post the link (or PM someone - if you do it in the next half hour I could take a look)

Okay, got it ...

With your demo project, it worked fine if I bought multiples of an item - when I trashed one, it would just trash one. But when I only had one of each item, and I trashed one, it wiped out everything, just as you said.

For some reason Galv has this:
Code:
  def multi_storage_set(item, amount)
    type = mstore_type(item)
    @storage[$game_variables[Storage::BOX_VAR]][type][item.id] ||= 0
    @storage[$game_variables[Storage::BOX_VAR]][type][item.id] = amount
   
    if @storage[$game_variables[Storage::BOX_VAR]][type][item.id] <= 0
      @storage[$game_variables[Storage::BOX_VAR]][type].delete_if { |key,value|
        key >= 0 # <<<<<<<<<<<<<<<<<<<<<
      }
    end
  end

which means as soon as you call multi_storage_set (which you do with store_rem), if it removes all of one item, it will delete every item where the key is 0 or greater.

I suspect it should be this instead:
Code:
  def multi_storage_set(item, amount)
    type = mstore_type(item)
    @storage[$game_variables[Storage::BOX_VAR]][type][item.id] ||= 0
    @storage[$game_variables[Storage::BOX_VAR]][type][item.id] = amount
   
    if @storage[$game_variables[Storage::BOX_VAR]][type][item.id] <= 0
      @storage[$game_variables[Storage::BOX_VAR]][type].delete_if { |key,value|
        value <= 0 # <<<<<<<<<<<<<<<<<<<<<<<<<<<
      }
    end
  end

So change line 875 and it should work fine.
Code:
value <= 0
That fixed it, thank you!
I then spent the day plugging each script from my project into the Demo project that Galv includes with the item storage script, and they all seemed to work fine there, so I decided instead to turn my attention to my own project. I've commented out every single script under Materials aside from Galv's item storage one, and yet still the store_rem call deletes everything in storage.
I think the confusion was just simply not doing the same thing.
When I tested galv's demo with placing one item of each into the box then talked to the guy next to the green chest he is supposed to remove the potions, but he removes all items.

I didn't test it that way, but I suspect that you were not reproducing the same conditions in the blank demo,

Either way, Shaz found the issue and yes that fixes it. Strange how Galv was using the key variable and not value at that point.
I didn't test it that way, but I suspect that you were not reproducing the same conditions in the blank demo,
Yeah, it didn't occur to me that the number of items in a stack would have an effect on whether the script call worked or not, lol. Live and learn I guess ^^
Strange how Galv was using the key variable and not value at that point.
I can only assume he must have been very tired that day, and also didn't test that particular scenario using that particular script call. Removing a single item via the storage window works fine as it calls a different function.

Original thread: https://forums.rpgmakerweb.com/threads/galv-item-storage-bank-bug.151689/