[Solved]Help with dynamic shop

I’ve been watching some tutorials on shops and they are great but they look like a lot of work if you have more than a handful of items or plan on creating more at a later date. Although I don’t mind work if that’s the only way to get it done. But is there a way to just have variables or groups for all your shop items. What will I need to learn to create more dynamic shops that just generate items, icons, text, cost etc. Also that when I click one tab of it, it can open and just show the items for that tab group. Sorry if this is not clear I’m new to this and not sure what lingo to use. Hope you can shed some light on it thanks.

You mean an online shop don’t you? for players to buy with real money or with other connected players?

Or an intern shop where the player buy and exchange things in the game world, with no online or real money interaction?

Oh sorry, an item shop for players to use their game coins to buy items to decorate their cafe with no online or real money interaction.

Ok. I’ve never did that, but here is how I’d do:

First you’d have a database of items with their prices, infos etc.
items.apple.info= “red and good”

I guess in your shop there would be one button (one object/sprite) per item that the player can buy.

  • put all these sprites into one group “items”

  • for each sprite, set an object variable for the item name called “name”. So for example the sprite button to buy apples will have its object variable name=“apple”

  • for each sprite, set an object variable for the item shop tab called “shoptab”. So for example if apples are in the first shop tab, set its object variable to shoptab=1

  • you’ll also have one sprite (button) per tab, and events that say "if player click on these tab, then set variable(currenttab) to 1, 2, or whatever…

  • run a For each loop, for each instance of group “items” :
    conditions : mouse is touching instance and instance object variable “shoptab” is equal to Variable(currenttab)
    → textobject “info” set to items[item.ObjectVariable(name)][“info”]

        • condition : mouse button released
        • → set variable “wanteditem” to the object variable (name), and check if purchase is possible

So, still inside this for each loop, you check, when conditions are met, if purchasing is possible:

  • if items[VariableString(wanteditem)][“price”] </= player.money
    then → player[“inventory”][VariableString(wanteditem)] add 1 ; and player.money substract items[VariableString(wanteditem)][“price”]

if not possible, set a message like “you don’t have enough money”

Ok this was for the player’s shopping. You’d also need events to display the right items’sprites depending on the current tab (events for the shop displaying). Use a ForEach loop for that too.

So taht’s how I would have done that. That way, every time you add an item to your shop, you basically just need to:

  • create a button sprite, give it object variables “name” and “shoptab”
  • place it on your scene, and add it to the “items” object group
  • add in you datas variables price and infos

Maybe people who already made a shop can give you a better way to do it. Or maybe there are already made examples.

In my description you have main lines, but you may want to improve it, with for instance, checking if purchase if possible before clicking, to freeze the button or set it red, etc. Everything is possible then :slight_smile:

1 Like

Once more, there must be better ways to do it.
At least my way can give you ideas about it. Good luck!

No i don’t think there are any examples except for this one you just did lol. Thanks so much this sounds like what I’m looking for especially being able to easily add more later, I really appreciate your help.

1 Like

Good! You’re very welcome, glad it can help :slight_smile: