Trying to create a simple item shop

Hello,
I’m trying to create a simple shop that the player can buy and equip items from. I’m creating the shop using a data table and a scroll box. The idea is that each item has a buy button with some text on and it when the player clicks the buy button the text changes between buy, equip and equipped.

My issue is that when the player leaves the shop the item text resets and I can’t figure out how to make this text data persistent when the player leaves and reopens the store. I’ve tried storing some bool variables in the game instance BP but that was causing some other issues.

This is what my shop looks like

Here’s the shop widget

Here’s the BP for creating each of the items for the player to buy

I have the button text bound to a function that updates when the player purchases or equips an item.

I’d also like to have the player to only be able to equip 1 item at a time so when they equip an item it should unequip an equipped item if there is any.

Any help would be much appreciated.

I would have some kind of inventory attached to the player that keeps track of items they have. Likely in a component. Items would be kept in an array as a struct of Item Name, ID, Is Purchased, and Is Equipped + any other data you need.

When creating the widgets on store load, you should be looping through all available “items” in the datable and creating widgets from that. During that loop, for each item, I would also check the inventory of the Player to see if they have the item, & if it’s equipped. You’ll query their Inventory Component for that. It would probably be better for performance if you simply use a list of “Equipped” & “Purchased” id’s. Create a function in the inventory that returns these values, save them as a variable in the item shop ui, then use them on the loop. Saves you from casting to an inventory an unnecessary amount of times.

If it is equipped/owned, you would set the text data right then. You could easily keep the inventory & UI in sync afterwards. You can also save the inventory data to save-game for persistence through sessions.

As for one item at a time, make a function that loops through all items the player owns looking for “is equipped”. Make that function switch the value to false & equip the new item.

Good luck!

Thanks for the information, this does sound like what I’m needing to do.

I created an inventory component and attached it to the player. I’ve also created the struct array using 2 id’s “equipped” and purchased". The next part is where I’m struggling with. I’ve added a for each loop in my shop UI when the shop is being created and added in the player inventory array.
Would you be able to further explain or provide an example of what this function in the inventory that returns these variables and how to add these variables into the inventory when the items are purchased/equipped?

Also for the button text should this be getting set in the for loop when it’s checking to see if the item has been purchased or equipped or should the text be getting set with a function binding?

Thanks again for any help!

I’d avoid using function bindings unless you need to. Remember it’s updating all the time. If you don’t need to have that, you should avoid & use a manual set.

Your struct array should also contain the ID of the item so you can tell what’s what. The function in the inventory is just going to look at the inventory array and spit out a list of IDs for anything that’s Owned or Equipped. You’ll use that data during the loop to set the text of each item correctly.