Need Help with script call for setting Inventory values

alphawiz

Veteran
Veteran
Joined
Feb 8, 2017
Messages
67
Reaction score
10
First Language
English
Primarily Uses
RMMV
I am working on a game where thru various interactions the player can gain/lose items which will either aid or adversely affect them in other areas. Due to the different plugins that I'm using and the way they interact, I find I have to have both inventory items and values in a Variable. It is vital that the numbers stay synced up, or all hell could break loose.

Therefore, I have a two common events set up. One to synchronize the variables with the Inventory counts and one to synchronize the inventory with the variables, depending on which values get changed in the various minigames or events. It is the latter that I am having trouble with.

I have tried several different methods, all of which give me an Undefined error. (see below)

$gameParty.item_number($dataItems[6].value).setValue($gameVariables[5].value);

$gameParty.numItems($dataItems[6]) = $gameVariables[5].value;

$gameParty.item_number($dataItems[6].value) = $gameVariables[5].value;


I can't use gainItem or loseItem because those functions only add or subtract a set number of items. I need to set the number of items to a specific value.

Can someone please help? I've been banging my head on this for a few days now.

Thank you!
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,366
Reaction score
7,676
First Language
German
Primarily Uses
RMMV
why not use the default control variable options for the numbers of items in inventory?
true, it means a long list of control variable commands - but from your description you're already doing it with such a long list, so nothing lost...
 

alphawiz

Veteran
Veteran
Joined
Feb 8, 2017
Messages
67
Reaction score
10
First Language
English
Primarily Uses
RMMV
Could you elaborate? The variables I'm using are control variables. I'm not having any trouble setting the values of the variables, just the values of the inventory items. I've looked thru dozens of web sites trying to find a way to set a value of the inventory item value and cannot find it.

I have to use the inventory items AND variables in order to utilize all of the plugins I need to use since some don't access the inventory and others don't use variables, so I have to keep them synched up.

In other words, what "default control variable options" are you referring to?
 

Aloe Guvner

Walrus
Veteran
Joined
Sep 28, 2017
Messages
1,628
Reaction score
1,115
First Language
English
Primarily Uses
RMMV
"Control Variables" is an Event Command:

2018-06-08 13_31_10-Window.png

Or alternatively you could do it like this:

2018-06-08 13_32_47-Window.png

Edit: I just re-read and noticed you are saying "inventory item value". Are you referring to the cost (Gold)? If you aren't referring to that, should I assume that you mean "count"?
 

alphawiz

Veteran
Veteran
Joined
Feb 8, 2017
Messages
67
Reaction score
10
First Language
English
Primarily Uses
RMMV
the item count. As in If I have 10 potions.

I can't use the control variable option. The problem with it is very simple. It only increases or decreases by the variable amount (or constant)
I need to SET the value. For example:

If I start with 5 tickets, and during the course of the minigame event gain 3 more for a total of 8, the value of which is set in a Variable.

Doing an Increase of the Variable value to the Item will make the total number of that Item be equal to 13 (5+8) not 8. So Control variable won't
work.

The whole point is to sync up two different numbers so that they match. I cannot believe that there is not a way to assign a value to an Item count and only increment or decrement it. In order to do it with control variables, I would have to set a starting value, in a separate variable, then subtract the change and then do a gainItem call. It's possible, but it's also going the long way around and completely violates the KISS principle instead of just being able to SET a value with an assignment.

Your example for setting the value of the Variable to match the Item count would work fine, but I'm trying to do the opposite, set the item count to equal the value of the Variable, which does not seem to have a direct way to do it that I can find. I'm hoping it's solely a matter of not being able to find the proper reference.
 
Last edited:

Tiamat-86

old jrpg gamer
Veteran
Joined
Dec 5, 2017
Messages
554
Reaction score
229
First Language
english
Primarily Uses
RMMV
that 1st screenshot will set the variable to 8 if u only have 8 of the item
because "set" is selected for the control variable, not "add".

if im reading into ur intent correctly, you might wanna look into this plugin
http://yanfly.moe/2016/01/22/yep-060-more-currencies/
This plugin requires YEP_ShopMenuCore.

this will allow u to use a variable as a currency.
in my game gold can buy just about anything but its not as easy to come by as killing monsters that wouldnt carry around useless gold coins.
on the other hand Residuum if a byproduct of alchemizing monster parts and is easy to come by. but is mainly only able to buy crafting materials with it

from the example i see of ur game. gamble for an hour u have say 40 tickest.
would then have a shop that only uses tickets for currency.
so like potion costs 1 ticket. iron sword costs 12 tickets

am i understanding the intent correctly?
 
Last edited:

Aloe Guvner

Walrus
Veteran
Joined
Sep 28, 2017
Messages
1,628
Reaction score
1,115
First Language
English
Primarily Uses
RMMV
Your example for setting the value of the Variable to match the Item count would work fine, but I'm trying to do the opposite, set the item count to equal the value of the Variable,
Did you look at my second screenshot?
 

alphawiz

Veteran
Veteran
Joined
Feb 8, 2017
Messages
67
Reaction score
10
First Language
English
Primarily Uses
RMMV
that 1st screenshot will set the variable to 8 if u only have 8 of the item
Yes, I *know* that. That is not the problem. I need to set the ITEM count to the variable value, which is the exact OPPOSITE of what that first screenshot does.

I need to make sure that the number of Items is equal to the variable, not the variable equal to the number of items.
Setting the variable value would have the net effect of wiping out the results of the game that the player just played where they won or lost. There are situations where the minigame does not update the number of items in the inventory (what can I say, the game wasn't written that way) It just increases the value of a Variable. This sync process I'm trying to do is my way of making sure the item is in the players inventory so that I can appear to use a single term. (Tickets)

I have an item called Tickets, I also have a variable called tickets. Some games don't give items, but instead return a number of points, for example. I need for number of item-Tickets to be set to the new number of point-Tickets so no matter which game the player goes to next, they can have the Tickets they need. It's like how some arcades use Tokens and some use quarters. This process is to make it so that the player always has an equal number of quarters and tokens no matter which arcade they go to.
 

Zarsla

Veteran
Veteran
Joined
Jan 23, 2015
Messages
710
Reaction score
228
First Language
English
Primarily Uses
As far as I know there is no script call that sets an inventory item to a set number. You have to do what I did here.

Screenshot (112).png

Now as for what I did.
First set a variable to be the number you want. In my example it's 7.
Then subtract the number of items that's in the inventory from the variable.
Then add that variable to the number of items you have and you have it set to the number you want.

Now as to how this works.
Well let's say the amount of magic waters in my inventory is 10.
7 - 10 = -3.
-3 is what the variable stores when I add it to the number of items in my inventory, it sets to 7. Why because 10 + -3 = 7.

Let's say the amount of magic waters in my inventory is 5.
7 - 5 = 2.
2 is what the variable stores when I add it to the number of items in my inventory, it sets to 7. Why because 5 + 2 = 7.

So in words what you need to do is figure out how far the amount of items you have in your inventory is from the specific number you want to set it to aka the "distance" between those two numbers. Then add that "distance" to the items in the inventory.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,366
Reaction score
7,676
First Language
German
Primarily Uses
RMMV
@alphawiz
OK, I now understand what you mean.
However I don't think there is such a command (wouldn't fit with the logic structures imho), so you'll have two options:
1) mathematically calculate the difference and then use the gain/loose functions on the difference
This will be require a few more steps instead of a single set command
2) request a plugin that adds that command (or even better that handles the entire sequence for you)
 

alphawiz

Veteran
Veteran
Joined
Feb 8, 2017
Messages
67
Reaction score
10
First Language
English
Primarily Uses
RMMV
Did you look at my second screenshot?
Yes, I looked at the second screenshot. It does exactly what I am not wanting to do. Adding (or subtracting) the number from what is there. The only way that would work is if I had another variable with the difference between the number of how many tickets I started with and how many I ended up with. (I presume it won't explode if there's a net loss and I increase by a negative number) But I'm trying to avoid the extra variables and operations if at all possible.
 

Tiamat-86

old jrpg gamer
Veteran
Joined
Dec 5, 2017
Messages
554
Reaction score
229
First Language
english
Primarily Uses
RMMV
sounds like another variable is exactly what ur looking for.
variable A to control ticket inventory amount.
variable B is the game result to increase or decrease the amount of variable A
theres no shame in using mutiple variable for 1 purpose.
just makeing a teleport and escape system requires 3 variables
 

Aloe Guvner

Walrus
Veteran
Joined
Sep 28, 2017
Messages
1,628
Reaction score
1,115
First Language
English
Primarily Uses
RMMV
Yes, I looked at the second screenshot. It does exactly what I am not wanting to do. Adding (or subtracting) the number from what is there. The only way that would work is if I had another variable with the difference between the number of how many tickets I started with and how many I ended up with. (I presume it won't explode if there's a net loss and I increase by a negative number) But I'm trying to avoid the extra variables and operations if at all possible.
You should actually try it. If I understand you correctly, you would like to SET the count of an item in the inventory to a given variable. It is doing exactly that.

1. Remove 999 potions (now you have 0 potions)
2. Add { variable } potions (now you have 18 potions, for example)
 

alphawiz

Veteran
Veteran
Joined
Feb 8, 2017
Messages
67
Reaction score
10
First Language
English
Primarily Uses
RMMV
Well...I was hoping it wouldn't come to that, but I guess it's time to add a few place holder variables that before each game, will store the current values so that I'll know what the original values were so I can get the net change.

This leads to another question.

Is it possible to have a negative item count or will it have a hard stop at zero?
 

Tiamat-86

old jrpg gamer
Veteran
Joined
Dec 5, 2017
Messages
554
Reaction score
229
First Language
english
Primarily Uses
RMMV
by defult hard stop at 0.
 

Zarsla

Veteran
Veteran
Joined
Jan 23, 2015
Messages
710
Reaction score
228
First Language
English
Primarily Uses
If you're using default rpg maker mv it stops at 0.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,366
Reaction score
7,676
First Language
German
Primarily Uses
RMMV
Is it possible to have a negative item count or will it have a hard stop at zero?
the default methods prevent negative items, that is why the tip with the "minus 9999" above works and why I said in my answer above that a set command doesn't fit the logic.

however, have you seen the second option I mentioned above?
 

alphawiz

Veteran
Veteran
Joined
Feb 8, 2017
Messages
67
Reaction score
10
First Language
English
Primarily Uses
RMMV
Thanks to all who replied. Hopefully I'll be able to get this thing working properly now.
 

alphawiz

Veteran
Veteran
Joined
Feb 8, 2017
Messages
67
Reaction score
10
First Language
English
Primarily Uses
RMMV
the default methods prevent negative items, that is why the tip with the "minus 9999" above works and why I said in my answer above that a set command doesn't fit the logic.

however, have you seen the second option I mentioned above?
About requesting a plugin? I saw it, and I might. Although, who knows how long it would take for one to be written and become available? I'd really like to have this game I'm working on ready sometime this summer. :) If one becomes available, I may do a rewrite though.

I don't agree with your statement about the logic though. Seems to me a SET command would be the perfect way to make adjustments to a number. But that's what makes the world go round...different opinions and Ideas. Although a SET type command would sidestep any potential issues should the defaults be changed or if another plugin overrode them. Best way to debug is to not put the bug in the code to begin with :D

Thanks for your help.

A
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,366
Reaction score
7,676
First Language
German
Primarily Uses
RMMV
@alphawiz
I was talking about the internal logic and security checks to prevent bugs, not how a function would work.
It's about capsuled programming - of course several methods to set data already exist, but they are encapsuled and would result in "undefined" errors if you try to use them directly.
And that is why such a plugin is not a large amount of work, it only needs to create a new function that redirects to the internal values that you currently can't change directly.

Read about object-oriented programming and classes as opposed to functional programming, and why global variables are not ideal for everything. And then you'll understand why the existing set-commands are intentionally blocked from your use.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

People3_5 and People3_8 added!

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.

Forum statistics

Threads
105,868
Messages
1,017,081
Members
137,582
Latest member
Spartacraft
Top