Adding an Item to a Variable

Hello there,

I am really new to RPG Maker MV and could use some help with something.
I have 5 items: Banana, Coconut, Pomegranate, Mango, Pineapple.
I want to assign all of them to a Variable and then have the game check if the Variable = 5 , it shouldn't allow me to acquire more of any of those 5 items.

I hope i explained what i need decent enough.

Thank you so much,
eredhar
'Turorials is where people who have made tutorials can post them.

Moved to: RPGMaker MV
Thank you for moving it. I apologize for posting in the wrong category.
do you want all items to 1 variable or to different variables?
so 5 items and 5 variables that check each item count.

if you want only 1 variable for all the 5 items, than it work a bit complicated, but do able.
and for what do you want to use it. so we can help you better in the direction you
want to go and avoid confusion.
do you want all items to 1 variable or to different variables?
so 5 items and 5 variables that check each item count.

if you want only 1 variable for all the 5 items, than it work a bit complicated, but do able.
and for what do you want to use it. so we can help you better in the direction you
want to go and avoid confusion.

Thank you for getting back to me!
I want 1 variable for all 5 items.
What i have is a barrel that you can search and it can give you one of the 5 items; at random. What i want is to limit the total amount to only 5.
Example: You can only carry 1 banana, 2 mango and 2 pineapples. OR: 2 coconuts, 3 mango. Basically I want to limit the combination of the fruits that you can carry to only 5, no matter which of the 5 items you have.
I can think of two ways to do this, each has advantage and disadvantage.

1.)
Use a script command to set the value of a variable, then check if it's bigger than 5 or not in the event.

Control Variables --> Script (at the bottom)
Code:
[11, 12, 13, 14, 15].reduce((acc, cur) => acc + $gameParty._items[cur], 0)
Where #11, #12, #13, #14, #15 are the ID # of your banana, mango, pineapple, etc. in the database. Change those numbers to your real ID#.

Now you can check if that Variable is bigger or smaller than 5 and do whatever you need to do with the Event Conditional Branch.

Advantage: only uses 1 variable
Disadvantage: that code above is confusing if you don't know javascript, you have to re-do it if you have different combinations

2.)
You can use this plugin which will always keep a Variable in sync with how many of a certain item you have.

Advantage: more obvious what it's doing and you can use standard event commands
Disadvantage: you need to use 6 variables (1 for each item, then 1 to total)

Actually it probably would not be difficult for me to update the plugin so you can use 1 variable to track multiple items...

Edit: third option is using Control Variables normal event commands to set the Variable value to the amount of an item possessed, then sum the variables together and check if it's greater than 5. That would be the most read-able and standard way but could be more work if you're doing this sort of thing often.
Thank you for getting back to me!
I want 1 variable for all 5 items.
What i have is a barrel that you can search and it can give you one of the 5 items; at random. What i want is to limit the total amount to only 5.
Example: You can only carry 1 banana, 2 mango and 2 pineapples. OR: 2 coconuts, 3 mango. Basically I want to limit the combination of the fruits that you can carry to only 5, no matter which of the 5 items you have.


I recently learned how to use variables to make a fear system for my game, in a way that, if the fear level is higher than 60 points, it will trigger a bad ending for the game, and good ending if the fear level is below 60 points. In your case, you can try to assign "fruits" as an item, and as a variable, and make a conditional branch. It will look sort of like this:

Capture.PNG

Capturff.PNG


Using this way, you can set it as "if fruits(variable name) = 5" (and only 1 fruit can be assigned as a variable using this way as i dont know how to assign 5 fruits"
Then, set it so that you wont be able to pick up any more fruits, I myself dont know how to make it so you cant pick up any more objects so i would like to learn more from this thread too XD
I can think of two ways to do this, each has advantage and disadvantage.

1.)
Use a script command to set the value of a variable, then check if it's bigger than 5 or not in the event.

Control Variables --> Script (at the bottom)
Code:
[11, 12, 13, 14, 15].reduce((acc, cur) => acc + $gameParty._items[cur], 0)
Where #11, #12, #13, #14, #15 are the ID # of your banana, mango, pineapple, etc. in the database. Change those numbers to your real ID#.

Now you can check if that Variable is bigger or smaller than 5 and do whatever you need to do with the Event Conditional Branch.

Advantage: only uses 1 variable
Disadvantage: that code above is confusing if you don't know javascript, you have to re-do it if you have different combinations

2.)
You can use this plugin which will always keep a Variable in sync with how many of a certain item you have.

Advantage: more obvious what it's doing and you can use standard event commands
Disadvantage: you need to use 6 variables (1 for each item, then 1 to total)

Actually it probably would not be difficult for me to update the plugin so you can use 1 variable to track multiple items...

Edit: third option is using Control Variables normal event commands to set the Variable value to the amount of an item possessed, then sum the variables together and check if it's greater than 5. That would be the most read-able and standard way but could be more work if you're doing this sort of thing often.


Hey and thank you for your suggestions. I tried the first one but got lost. I don't know java. I'll try to figure out the 3rd one, or if you can help me with the plugin?
What am I doing wrong here?
I still can't get this to work. Any help would be so appreciated.
What am I doing wrong here?
A lot of things.

1) a range operation means that every variable in that range gets the same operation.
So your sixth control variable command, control variable 06..10 = fruits total overwrites all five variables with the number in "fruits total", which is probably zero because it is never defined anywhere.

2) a parallel process loops once per frame, that is sixty times per second.
Which means that if the total were ever high enough, the player would be unable to move because he'll constantly get a show text in the face, and whenever he confirms it the next one will follow 1/60th second later.

Parallel processes are a bad way to check data and should only be used if there is no other method.

What you need to do is to have your barrel event check the numbers before it gives another fruit, and you need to use only one variable for that - but you need to ADD to that variable. The first command needs set to overwrite previous values, then only add.

control variable total fruits = number of Banana
control variable total fruits += number of Coconut
control variable total fruits += number of Mango
conditional branch: if total fruits >= 5 then
show text "full"
else
add fruit whatever
1) Is there a reason why you need a variable for each fruit?
2) Why not make one variable called "fruit_count?"
3) How do the players acquire more fruit?
4) Are the fruits consumable?

The idea is to build two events. One to increase the fruit count, and one to decrease it. Both could be a common event that is called when the fruit is acquired and when one is used. The "increase event" should be placed in the event that gives the fruit. This would also contain the "IF" statement if the count reaches 6. It would not have to be run a parallel event.

The "decrease fruit" event would be placed on the item in the database under "Effects, Call Common Event."

This would +/- the variable. The reason for using a common event is for easy updating. If something has to be added/changed/removed, it's a lot easier then trying to find all placed events.

Set a small test area on your map with everything setup. Then run all possibilities until it works as intended.

Original thread: https://forums.rpgmakerweb.com/threads/adding-an-item-to-a-variable.114596/