Script for storage problem

I'm testing an idea I had for an item storage system. (I know they are a lot of work, I haven't fully committed to this idea yet lol)
So far it's working but I've run into one problem. If the player has 90 cookies and over 100 in storage, how do I withdraw only 9 cookies?

Same in reverse. If I decide the player can only store 999 cookies, how do I deposit cookies and stop at 999? The player loses cookies in the process.

I figure this is maybe script related.
Thanks for reading.
Withdraw:
Set variable A to the number of cookies the player could possibly hold (99).
Subtract from variable A the number of cookies the player is actually holding (90).
Leaves you with 9 - the number of cookies the player can take from storage.
Set variable B to the number of cookies IN storage.
If A is less than B, then the player can take A cookies (9).
If B is less than A, then the player can take B cookies.

Deposit:
Set variable A to the number of cookies that can be stored (999).
Subtract from variable A the number of cookies that are actually in storage.
Set variable B to the number of cookies the player currently has.
If A is less than B, then the player can put A cookies into storage.
If B is less than A, then the player can put B cookies into storage.


In both cases, it's all done with Control Variables and Conditional Branches.
Hello!
The storage of cookies may end up expiring, try to create an Object or Array within the game's own variables:
JavaScript:
$gameVariables.itemStorage = [];

The order of each array will be equivalent to the item ID, thus being able to separate, similar to the classic monetary bank made with Events.

I don't know how to explain a lot why I don't know how you are actually doing this system.
But in this example, the item limit you can take out of storage is calculated using what you have with the party:
JavaScript:
var item_lmt = 99 - $gameParty._items[selected];
("selected" is an example of a menu variable or any method you used to create this system.)

Good luck
I assumed "cookies" just referred to an item in the game, not the internet-type cookies you get from browsers.
@Shaz But you're right, I got it wrong.
Spoiler
Sorry, I couldn't stand it, I spent about 2 minutes laughing at my misinterpretation.
cookie monster.jpg
Just to confirm - are you doing this all via eventing, or are you using an item storage plugin? If you're using a plugin, my suggestion will still be close, but you'll need to do something slightly different to get the number currently in storage and the maximum storage capacity.
Just to confirm - are you doing this all via eventing, or are you using an item storage plugin? If you're using a plugin, my suggestion will still be close, but you'll need to do something slightly different to get the number currently in storage and the maximum storage capacity.

I'm trying to do this via eventing to see what it's like. I was using the command
◆Change Items:Cookie + {99max var A}

but I haven't succeeded in making the event work and didn't want to bother anyone anymore till I re read what you posted and kept play testing. (Because the odds are I'm doing something wrong)

So I'll just keep at it. If I still have problems, I'll post up a screenshot and if I finally put the event together correctly, I will update the post to let everyone know I got it working.
What is {99max var A}? Did you actually put that into the script box? That is not Javascript syntax so will not work.

You would need to do it via variables as I showed you anyway, because you will have to add a variable number of cookies to the player's inventory, and deduct the same variable number of cookies from storage, so it's going to take 2 commands.
What is {99max var A}? Did you actually put that into the script box? That is not Javascript syntax so will not work.

You would need to do it via variables as I showed you anyway, because you will have to add a variable number of cookies to the player's inventory, and deduct the same variable number of cookies from storage, so it's going to take 2 commands.

It is when I copied as text using Rpg Maker. (And then pasted here) The 99max var A is the name of the variable. I guess when you copy and paste code from RPG maker MV they add syntax? You can right click copy as text in Rpg Maker.

I was using the command to change items based on variable. (And I named it var A so I could have a visual...^^)

I've been busy and have not gotten back to this. I think it's one of those errors that should be obvious that's misguiding me. Your post looks great so it's obviously an error on my end. When I have the time I'll look over my event again.

I'm not using script or javascript. Just trying to do what you posted. Thanks btw! When I get it working I will update this post.
Can you post a screenshot of your event?
I think I understand the concept but I'm having trouble wrapping my brain around how it is actually done.

Also is there an easier way to get screenshots from Rpg Maker MV?

Thank you for taking a look.
Apparently you can select the event commands and right-click, and there is a copy to text option. Then you can just come here and paste.

It's a bit hard to tell what your variables are, and whether you're using the same variable in multiple places. Would you like to zip up your Map###.json file and your System.json file and send them to me? That will let me look at the event and the variables. If you like (and it would be easier for me) you can create a brand new map and just copy this event onto it.
I know how to zip a file but can that even be uploaded here? I feel like I'm causing you too much trouble than it should. It's my fault I'm having trouble understanding.

Would it also be easier if you just redid your post here?
Withdraw:
Set variable A to the number of cookies the player could possibly hold (99).
Subtract from variable A the number of cookies the player is actually holding (90).
Leaves you with 9 - the number of cookies the player can take from storage.
Set variable B to the number of cookies IN storage.
If A is less than B, then the player can take A cookies (9).
If B is less than A, then the player can take B cookies.

Deposit:
Set variable A to the number of cookies that can be stored (999).
Subtract from variable A the number of cookies that are actually in storage.
Set variable B to the number of cookies the player currently has.
If A is less than B, then the player can put A cookies into storage.
If B is less than A, then the player can put B cookies into storage.


In both cases, it's all done with Control Variables and Conditional Branches.

I think it would help me if Variables A and B had names. For a visual. It looks like four variables are used for this kind of event.

1. The number of cookies held
2. The number of cookies in storage
3. A number to ensure you don't go over the max of 99 or 999
4. What number the player inputted

but I don't see where would Change item based on the variable would go? I thought variables would help determine how much items are deposited or withdrawn with a conditional branch that checks for certain conditions.
I guess I don't understand how to set this up. Could someone please show an example event?

I have tried in the past to set it up doing this
Withdraw:
Set variable A to the number of cookies the player could possibly hold (99).
Subtract from variable A the number of cookies the player is actually holding (90).
Leaves you with 9 - the number of cookies the player can take from storage.
Set variable B to the number of cookies IN storage.
If A is less than B, then the player can take A cookies (9).
If B is less than A, then the player can take B cookies.

Deposit:
Set variable A to the number of cookies that can be stored (999).
Subtract from variable A the number of cookies that are actually in storage.
Set variable B to the number of cookies the player currently has.
If A is less than B, then the player can put A cookies into storage.
If B is less than A, then the player can put B cookies into storage.


In both cases, it's all done with Control Variables and Conditional Branches.


I get the concept idea but I'm confused as to where to place "Input" and how many variables are actually being used. Like, 2 variables for A and B or 3 variables with the third being the amount of cookies the player posses?

If someone would kindly please show an event with the set up above that was suggested, a visual would really help me. Thanks.
I could try to get a round of this, as number input goes mostly below
the variable MAX in inventory, than check storage.

I wonder why you dont use a plugin (waynee) which has a nice one.
if you have max item to hold = 99, you cannot withdraw more than
that.

if you want pure eventing, how many items do you have to place in
the storage?

I might have something like that, if I can find it still , as I cleaned alot
from desktop, and folders, so I might have it for use, maybe it require
adjustment, depending on the items, unless it's something to place
to trigger something?
I wonder why you dont use a plugin (waynee) which has a nice one.
if you have max item to hold = 99, you cannot withdraw more than
that.
Because I like to see how it looks in Rpg Maker Mv first I guess? Plugins weren't always a thing and I want to set up an event one first. ^^;

I'm thinking something simple like the fridge sprite from Mv's SF tileset.
And then a simple message that asks "This is a fridge. Do you want to store something?"

And then choice A,B,C,D.
IE:
Choice 1: Cookie
Choice 2: Apple

Doesn't have to be every item in the game, I just want something simple like that. The ability to withdraw & deposit items. I'm okay with the 99 limit too.
limit can be anything, might require some variables, I see if I can find
it if I have it, else I try to replicate a simple setup for you 🙂

if scriptcalls are oke too, it can make things a bit easier too.
(unless someone else created it before me), as I know there are
many methodes to accomplish it.

Edit:
I got a basic bank system left, but lost the storage one.
as those are basicly the same, max items is different.
but it is like shaz said.

I see if I can fiddle something for you.
limit can be anything, might require some variables, I see if I can find
it if I have it, else I try to replicate a simple setup for you 🙂

if scriptcalls are oke too, it can make things a bit easier too.
(unless someone else created it before me), as I know there are
many methodes to accomplish it.

Edit:
I got a basic bank system left, but lost the storage one.
as those are basicly the same, max items is different.
but it is like shaz said.

I see if I can fiddle something for you.

Thanks so much! Just whenever you have time, I'm in no rush. I wasn't able to follow Shaz's Deposit and Withdraw event set up. ^^;
I make it a bit different, for now, it only store and take out items.
(no limit yet), I will impliment shaz idea inside as well if this works
correctly.

you can take a look at the basic setup if you like, I send later the rest.
this has no scriptcall for simplicity, otherwise, you can store all
items in a variable array.
I just dont know how to max those out yet, as low knowledge of JS.
so it can be better system for x items.

the way I set up, require basic 3 variables, so + 2 for each item,
than duplicate each common event into a choice (cookies, apples, carrots,
milk, eggs etc), so each items use 5 variables (if you can spare them).

I got the basic done, and works, I impliment the max items tomorrow around
for you.

send it here (2 files), map002 and common events which you can place
in a clean project. to check out the event setup.

Original thread: https://forums.rpgmakerweb.com/threads/script-for-storage-problem.136223/