For an RPG demo that I am currently making, I need to make a shopping widget. I have recently made a set of BP nodes which works with a map structure containing items and their respective quantities, as well as currency.
Now, how do I set up a shopping widget that allows the player to choose an item and set the desired quantity? This is an early version of the widget I have set up.
Previously, I set the widget to add 1 to an item’s quantity and take away 10 from the currency until the currency is less than the cost. The other button decreases the quantity by 1 per click. So, where do I go from here?
Here’s the BP I have so far, for a confirmation button I have just added. But, I’m not sure how to add the “Desired Number” to the “Quantity” integer within the map struct. Any suggestions?
First, I would advise you to make an inventory in the form of a map container (id, int).
All detailed information should be stored in a data table or data asset, and by id you get access to extended data when it is needed to fill a widget or create an item.
You should not store all information about an item in the inventory.
This is not necessary, and besides, if you expand the project in the future and change the parameters of objects, your save files may break.
I was given a recommendation in this previous thread – Gameplay Tags - Item Quantities – to use a map struct for the inventory list. So this widget is designed to update it through buying, selling, etc. It is also based on a preexisting jRPG template which I found and downloaded off the Epic Games Marketplace, but with my own changes to the data table and to the structure.
So, just to confirm, are you saying I shouldn’t use a string for the structure like in the previous thread and in the BP above?
As an id (key) you can use any data type (string, guid, data asset reference, name (for data table row))(depending on which storage you choose for description).
The main thing is that you do not store the description of the item parameters in the inventory (value), only their quantity.
I have the key for a specified item by name. Right now, the item button I have is focused only on one item; I will do one that covers multiple key items in a later version of this widget.
The quantity is the only thing I want to update per purchase or sale; so, given that this is an integer, what would be the best way to do so, if the Desired Number is a separate integer used to add to or subtract from some item’s Quantity? Any screenshots or tutorials for examples?
I think I know what you’re talking about. By changing that string map to a name one and including only the necessary variables - ItemName and Quantity - I could make finding those variables much simpler. But how would I still go about, adding the DesiredNumber to the Quantity in some item after a completed purchase?
This is how I currently implement it. First, I have a dictionary of all items, and then the NPC and the player each have a backpack. If the NPC is a merchant, then he also has a store backpack. My NPC merchant will regularly update the inventory of the store backpack (product ID and corresponding quantity, and balance). When displaying the backpack, it will find the detailed information of the item from the dictionary based on the ID (including name, description, price, etc.). When the player buys or sells an item to the merchant, the code will check whether there is enough quantity of goods and whether there is enough balance. If the conditions are met, the number of goods held by one party will be reduced and the number of goods held by the other party will be increased, and then the balance of both parties will be updated.
I always thought the merchant had an endless supply in most RPGs, so I was going with operations that focused on the player’s party. That is, reducing Gold (which will have a different name in a later version) as the Quantity of some item increases until either there isn’t enough Gold or the player has too many of a particular item.
Anyway, do you think I should make both a name map and a string one? Or just a name one?
I forgot to show you. This is what I have set up for adding and subtracting one item at a time.
So, if I need to change the struct map to a different variable, where do you suggest I declare the ItemID text variable and how do I set that up? (Ignore the Boolean variables, as they were from an earlier version. I need to delete those.)
You need to change your Inventory Stash map to the Name-Int type.
Then you create a Data Table with an Inventory Struct structure and fill it with item descriptions (item name needs to be removed from the structure, instead of it there will now be row name from data table).
When you need to get a description of an item, you take Data Table->Get Data Table Row and get your structure with a description of the corresponding item by its name (row name).
You only need to delete ItemName (the one that was the item id before). Instead of it, Row Name from Data Table is now used.
Instead of NewRow you should write your item name (id).
Click on it (the one on top) to change it.
The visual name of the item and the description remain unchanged.
FIX: ItemName and Quantity. Remove these variables in the structure, you don’t need them at all in the data table.
You will store the number of items in Inventory Map (Name,Int).
The Data Table stores (should store) information about all possible types of items, not about their quantity in your inventory (or anywhere else). You will also take information from the Data Table when filling in available items in the store.
I’m sorry. I thought you said to make two separate ones, but my mistake. Anyway, if I remove the quantity, how will the program (and the player) know how many items are in possession?
Edit: I think I’m beginning to see what you meant by using a Name-Int variable. That alone tells how many of some item the player has, right?
It also occurred to me. I can’t seem to get the cost from the table via this variable, so I can’t get the program to calculate how much gold is to be subtracted per purchase.
Naturally you need to add a check that you have enough money and there is space in your inventory (if it has a limited size), or any other restrictions on buying/selling.