I’m not totally sure if this is right, but here is what I have so far.
You need to subtract the variable Cost from the variable Gold.
Now you subtract the money you have FROM the price of ONE item.
You must subtract the price of MULTIPLE items from the money. You set this price in the variable, just subtract the Cost value from the Gold.
Here is the blueprint so far, focusing on the Item and Confirm buttons only. Since this widget is still in its testing phase, the Item button is supposed to invoke only the data row with the name BottledWater. That is why I set the Item ID to BottledWater. In a later version, I will make multiple buttons that will assign the Item ID to whichever item.
In an attempt to make sure the program calculated correctly and gave me the right results, I threw in a Print String with the intention of the program’s printing the Gold integer at the end of the sequence. But it seems to be stuck on 95, with Gold’s Default Value set to 100. Maybe I shouldn’t have promoted the Gold from my Game Instance BP as a variable for this widget.
At the bottom, after AddMap node, remove the Set Gold node. It is not needed there.
At the top, replace the Gold variable from the widget with the Gold variable from Game Instance.
After making the changes, I think I’m on the right track. But there are still a couple of problems. The two “Print String” nodes are marked with comments. It seems the program calculates on the top sequence but not really in the bottom. I feel like the set of nodes on the bottom is missing something or isn’t placed in the proper order for some reason.
There we go. Got it working as needed. Thanks for the help, so far! Now to set up individual item buttons.
While we’re on topic, what would be the best way to set a list of items on a shopping widget? I’d also like to set it to where the player can browse using a keyboard or a mouse.
Also, how do I know the player has at least one of some item? I’m asking this so the widget will be able to detect if he has any items to sell; and because of a dialogue scene that will check for certain items and the correct number of each.
It depends on what design you want, but most likely it will be a Vertical/Horizontal Box or Uniform Grid Panel located inside a Scroll Box.
To do this, you need to call the Set Keyboard Focus function (and/or (I don’t remember exactly) Set Focus for the ITEM widget (an element inside a Vertical Box or Uniform Grid Panel)) to enable keyboard control. The widget must have the Is Focusable flag enabled.
Via the Find function in your Inventory Stash map. When you create an item widget, you will have its ID, just check for it.
I’ve made a widget to show the inventory, but all it prints is “0.” I feel like I’m missing a lot of things. I’ll especially need to get the program to keep track of what the player has so I can start working on the Sell Button.
Well, that’s quite predictable, you didn’t put an item named ItemID into your inventory, did you?)
You need to get an array of Data Table row names. Then create a loop over that array. Inside the loop, create a widget for each item for your store and check if the item name from the loop item is in your inventory.
Should I make another map variable with the names? Or just an array variable that derives from the Inventory table?
Also, are you saying I should make a widget for each individual item? With integer variables so parts of the game can check for those variables for related items?
This. Using the appropriate function:
Not really. You create ONE widget class for all items (with name, icon, description, etc.).
But you will create a new INSTANCE of this class for each item.
In the item widget, create variables for name and quantity etc. Set the Instance Editable and Expose On Spawn flags so they appear as pins in the creation node.
In the Item widget, using Event Construct, set the value from the variables for the corresponding Text widgets displaying the name and quantity of items.
You can either pass the name of the item to the widget and get the information from the Data Table again, or create a variable for each item parameter and pass the ready-made data to the widget, it doesn’t matter.
Something like this, for the intenvory widget?
Though I’m pretty sure this isn’t totally right. For one thing, it’s missing a Target on the end, and I can’t attack the Item Widget as such. Getting a copy wouldn’t work either, I’m guessing.
Here is what I have for the Item Widget, with the two variables declared and checked as specified. Though I’m not quite sure what you mean by “similarly for the name.” Does that mean I use something like what’s in the screenshot to print out the name and quantity of each item per row?
You should create a Vertical Box in the Designer tab of your store widget, and connect the reference variable to this Vertical Box to Target (similar to how you connect Target when setting the text).
You need to create another Text widget (TextBlock 1) in the item widget and call the Set Text function for it, but as a value you need to connect not the number of items, but the name of the item.
And the fact that the array pins of names from the Data Table and the Loop are not connected, is this a display error, or did you not do this?
They MUST be connected.
After making the suggested changes and creating the vertical box, the program technically works. But I’ll have to fix the appearance.
My bad. I overlooked that part. Though I don’t appreciate being talked down to.
I’ve also set the Inventory screen to not show any text if the quantity of any item is 0, after setting the text blocks to be blank by default and centering the narrow vertical box. Though I’ve hit a snag in putting in an exit button to close the widget because the button has been replicated. Is there a way I can get the widget to replicate the table rows but not the button?
This is what we all want to get here, and that’s great.
I’m less lucky with answers to my questions
I don’t quite understand why you decided this, but it was definitely not intentional
I didn’t quite get you. Do you mean network interaction? Widgets don’t have replication, if that’s what you mean.
Sorry, got a little sensitive. Anyway, here’s what I mean by the replicating part.
Anyway, here’s what I mean. What I might do is make a separate widget that appears at the same time, and the button could close both of them at once when clicked.
Actually, I got this part figured out. I made a separate widget that just has a clickable button to close both widgets, using this BP.
But now I’ve run into yet another snag.
I only want item names and numbers to be displayed if the player has at least one of each; I don’t want any items with its Quantity at 0 to appear. How might I fix that?