Copy a list of things and connect it to a user

Hello, I’m trying to make a default inventory that all my users (players) will create once they load the page, that will automatically update if I add an item. Here’s my example.


As you can see, there is a list on the bottom that isn’t connected to a player. This is my stock inventory that everyone will need to add.

I used the below workflow to copy the inventory that isn’t connected to a player yet (my stock inventory) and made changes to connect it to the current player.

This works to copy the list and connect it to the user, but the issue is I need to figure out a way from here for it to check whether or not the player currently has an inventory item, and if it does not to update that item. Right now if I reload the page it adds all of the items again. I want there to be no duplicates.

If there is a way to do this I haven’t been able to figure it out. Maybe I’m missing something in the copy list function. If there is an easier way to create a default set up items that can be placed on each player (and updated) I’d love the insight.

Thanks for any help, I’ve been beating my head against a wall on the best way to do inventories for weeks.

I GOT IT! I didn’t realize there was an advanced function! Nice :slight_smile:

Here’s the solution if it helps anyone else.

Ok…now it isn’t connecting to my user haha. It is copying the list correctly, but I’m not exactly sure the best way to connect this to my player. Back to the drawing board but I think I’m on the right track.

Added a step to add to my users inventory, which works, but now I’m getting duplicates again on page reload.

image

I think it’s considering the stock inventory different from the ones in my inventory, since my inventory items contain a “player” field making them different. This is making my advanced filter not work correctly since they aren’t technically the same.

I’m also a touch worried that “copy a list” isn’t going to work long term since it won’t allow me to build more than 100 items to copy. If I end up building more than 100 items this method becomes moot… hmm

Hi there, @snarec… if I understand your post correctly, I wouldn’t copy a list of things, but instead, I would use a recursive backend workflow that loops through a list of the default inventory items and creates a new item for a player for each item in the default list. I would probably also have a field that links each item for a player back to its default item. With that field in place, you could define the list of things that need to be created for the player (which you will pass as a parameter to the backend workflow) as the default list minus a list of items where the player is the current user and the item’s associated default item field contains an item in the default list.

So, any of that make sense and seem like it could work for you?

Best…
Mike

For a backend workflow would I need to up to a more expensive version of bubble? I thought I had read that somewhere. If not, I’ll start trying to figure out what your post means haha.

Yeah, you would need to be on at least the first paid plan (Personal) in order to use backend workflows. If you can swing it (no offense there, of course), I would highly recommend it because backend workflows will change your life (well, your Bubble life, at least). To be honest, you almost can’t build an app “the right way” without backend workflows, so you are probably going to have to go that route at some point anyway.

Ah, I’m on personal already, good deal :slight_smile: I’ll start working through your suggestion thanks!

Aw, yeah! Head over to your Settings >> API tab and enable them there, and start gettin’ your learn on. Now the Bubble fun really begins!

1 Like

If it helps, here is an example you can use for reference.

Here is the backend workflow and the default inventory list parameter.

Here is the workflow on the front end that runs on page load and calls the backend workflow.

The constraint on the first search looks like this.

Note that I used a yes/no field (set to yes) to define an inventory item as a default item instead of looking for an empty player field, and I probably wouldn’t have the player field at all because the built-in Created by field will associate an item with a player.

The constraint on the second search is the same as the constraint on the first search, and the advanced filter looks like this.

Note that the constraint on the search in the advanced filter is Created by = Current User.

Finally, the actions in the backend workflow look like this.

I can’t actually test that stuff because my sandbox app is not on a paid plan, but even if it doesn’t fully work, it should help you understand some of the concepts you will need to keep in mind, such as putting a condition on the second step of the backend workflow to stop it from looping at some point.

I’m running into an error here-

for clarity, I called “Inventory” - “Inventory Item” and “Default Item” “Default”.

Your advanced filter seems to work while mine is coming up with the issue “:filtered: value should be yes / no but right now it is a empty” I’m not sure how yours is different from mine

What is the field type of your Default field?

It’s a Yes / No

You’re comparing the wrong things. Look at my example again… my default and default item fields are different, and they both exist for a specific reason.

I’m not seeing anything in your example explaining what the default item field is? Did you add that to your inventory data type’s fields?

Oh, right… the explanation of that field is in a previous reply.

That field is an important piece of my example.

hate to keep bothering you… I got everything copied exactly as you have it, but I’m running into an issue. The way it is now it runs and I get this.

It seems to run once but doesn’t actually copy the information correctly. To test, I changed the default inventory list to this-
image
Which gives back this-

Which is what I want, except that on each refresh, I’m still given an empty inventory item. I refreshed two more times and this is what it looks like

Any insight there?

Without being able to see exactly how you have everything set up from end to end, I don’t know what’s going on. If you want to share a read-only link to your editor, I’d be happy to poke around under the hood.

1 Like