Easy script: storage up to 4 items not working help

I'm sure this is a very easy fix but I'm way too tired to figure it out right now and I need to complete this tonight aha.

I have a bucket that the player can store fish in and take fish out of again, up to 4 fish.
If you put 4 fish in however, the script stops working. It displays"there are now 4 fish in the bucket" then "there are already 4 fish in the bucket" and then neither put fish in nor take fish out work. I haven't ended it properly. Pls help my sleep addled brain.
This is the script:

Put fish in, take fish out
When put fish in:
Con branch var "fish in inventory" >0 else "you have no fish"
Con branch var "fish in bucket" = 0 text: "there is now 1 fish in the bucket." var. "fish in bucket" +1 var "fish in inventory" -1
else: next conditional branch
Con branch var "fish in bucket" = 1 text: "there are now 2 fish in the bucket" var. "fish in bucket" +1 var "fish in inventory" -1
else: next conditional branch
Con branch var "fish in bucket" = 2 text: "there are now 3 fish in the bucket" var. "fish in bucket" +1 var "fish in inventory" -1
else: next conditional branch
Con branch var "fish in bucket" = 3 text: "there are now 4 fish in the bucket" var. "fish in bucket" +1 var "fish in inventory" -1 else: next conditional branch
Con branch var "fish in bucket" = 4 text: "there are already 4 fish in the bucket" end.
When take fish out:
Con branch var "fish in bucket" >0 else "there are no fish in the bucket"
Con branch var "fish in bucket" =1 text "you take a fish from the bucket, now 0" var "fish in bucket" -1 var "fish in inventory" +1
else: next conditional branch
Con branch var "fish in bucket" =2 text "you take a fish from the bucket, now 1" var "fish in bucket" -1 var "fish in inventory" +1
else: next conditional branch
Con branch var "fish in bucket" =3 text "you take a fish from the bucket, now 2" var "fish in bucket" -1 var "fish in inventory" +1
else: next conditional branch
Con branch var "fish in bucket" =4 text "you take a fish from the bucket, now 3" var "fish in bucket" -1 var "fish in inventory" +1
Writing your event with no indentation makes reading it incredibly difficult. However, from what I can see, you are using a lot of unnecessary branches. In computer science there is a golden rule of thumb that states:
"Never write the same thing twice if you can avoid doing that".

In your event you have a different conditional branch for each fish you have in your bucket, that goes completely against that rule. You have two situations here:
  1. the player tries to put a fish in the bucket;
  2. the player tries to pull a fish out of the bucket.
The only three borderline cases are:
  1. there are already 4 fishes in the bucket (when you try to put a new fish in the bucket);
  2. there are no fishes in the bucket (when you try to pull out one);
  3. there are no fishes in the player inventory (only when trying to put one in the bucket).
In the end, the borderline cases 1 and 3 refer ONLY to situation 1 and the borderline case 2 refers ONLY to situation 2. Nothing else matters. After this premise, let's see how to handle this.

- - - - - - - - - - - - - -​

How to handle this
To handle this you only need a single variable that stores how many fishes are already stored in the bucket. That very same variable can also be used in your message to display the number of fishes in the bucket. There is no need for a different conditional branch each time.

  • Prepare your interactions
To prepare your interactions you need a choice: the player has to decide what he or she wants to do with the bucket. The two choices are the two situations listed above.

Heirukichi said:
You have two situations here:
  1. the player tries to put a fish in the bucket;
  2. the player tries to pull a fish out of the bucket.

When the player casts his or her choice, you have to handle the borderline case accordingly using a single conditional branch for each different choice.

  • Borderline case 1: THE BUCKET IS FULL
    If the bucket is full, it means that the variable where you stored the number of fishes in the bucket is already equal to 4. Just in case, it is usually better to use ">=" instead of "==". If the bucket is full, you simply display a message saying that the bucket is full, if it is not, you check if the player has any fish and, if he or she does, decrease the number of fishes in the player inventory and increase the variable by 1. You can then display a message to notify the player about the result of this action (either positive or negative). On top of it, there is no need to check the number of fishes in the player inventory. As long as there is at least one, you can perform this action. Just check it with a conditional branch instead of storing it in a variable.

  • Borderline case 2: THE BUCKET IS EMPTY
    If the bucket is empty, it means that the variable used to store the number of fishes in the bucket is 0. This is always true if you did not increase the variable before because variables are initialized to 0 when a new game starts. If it has a value different than 0, it means that you already used that variable. If the variable is bigger than 0, you can decrease it by 1 and increase the number of fishes in the player inventory, if it is not (which means it is smaller than or equal to 0), you display a message saying that the bucket is empty. If the action is successfully performed, you can display a message to notify the player about that.

- - - - - - - - - - - - -​
Spoiler: How it should look like
Final Result
The final result is a much shorter event that looks like this (I am using variable 40 in my example, you can use a different variable):
Code:
@> Show Choices: Store a fish, Get a fish
:  When [Store a fish]
   @> Conditional Branch: [Fish] in inventory
      @> Conditional Branch: Variable[0040:StoredFish] >= 4
         @> Text: -, -, Normal, Bottom
         :      : The bucket is full.
      :  Else
         @> Control Variables: [0040:StoredFish]  += 1
         @> Change Items: [Fish], - 1
         @> Text: -, -, Normal, Bottom
         :      : You put a fish in the bucket.
         :      : There are now \V[40] fish in the bucket.
      : Branch End
   :  Else
      @> Text: -, -, Normal, Bottom
      :       : You have no fish.
   :  Branch End
:  When [Get a fish]
   @> Conditional Branch: Variable[0040:StoredFish] > 0
      @> Control Variables: [0040:StoredFish] += 1
      @> Change Items: [Fish], + 1
      @> Text: -, -, Normal, Bottom
      :       : You take a fish from the bucket.
      :       : There are now \V[40] fish in the bucket.
   :  Else
      @> Text: -, -, Normal, Bottom
      :      : The bucket is empty.
   :  Branch End
:  Branch End

This way it is much easier to read the event and to manage it in the future if you decide that you need to change how it works.
Oh god thankyou it's 3am and I'm over-complicating everything lmao bless you
@Queerpg
If your query is fully resolved, please Report your post and ask for the thread to be closed. Mods might not see a post, but they will see a Report.

As I'm here, I'll do it for you now.

Thread closed IgnoreMe

Original thread: https://forums.rpgmakerweb.com/threads/easy-script-storage-up-to-4-items-not-working-help.111405/