Create Dynamic buttons from TinyDB post

Hello there!

I am creating a character Tracker for a boardgame.

I have created the stat-page with success. and saving it to Tiny DB.
I have set up so everytime the user saves a character, a tag with the name of the character as a value.

Now the issue, in the page "Saved characters, i want to create a dynamic button, that will pick up every Tiny DB with the tag “Character” and save it with the value from the tag. and if a new character is created a new button with the new name will pop up, and the old is stil present.

Can anyone help me with this?

Hi Ralfsi,

Welcome to the Kodular community!

Could you better explain how you structured the data?

You create a tag for each character with the character name as the value, but what are you actually setting as the tag each time?

There is about 25 stats, they are all tagged the name of the character and a ending

Ny idea was when i call for the stats, i can remove the ending and easily fix.

ny idea was that if i tag it with the name it will post to every stat too..


I haven’t fully understood yet :grinning_face_with_smiling_eyes:, but you could use dictionaries, no?

The thing is that there’s six races, that gives different bonuses, 9 professions, and everything changes the stats​:laughing:..

I want the funktion to just get the name as an overview, and potentially be able to have 100+ characters.

So would it be a problem to modify all the blocks to accept dictionaries? In that sense?

But it would be much more convenient, also because, being a very popular file extension, you could easily migrate the data to a server.

this might be the sollution, i will test soon.

Why use a dictionay instead of DB? what is the pros with using TinyDB?
i need it to be persistant

A dictionary is a set of data made up of a key and a value, like in TinyDB.

Its advantages are:

  • it’s a single file
  • it’s a JSON (a file format used by practically any platform) which, as I explained, can be easily integrated into a server.
  • data is easily obtained through the blocks get value for key and get value at keypath, as in the example I showed you
  • And just as you can easily retrieve the data, you can also write data with the blocks set value for key and set value for keypath
  • data manipulation is much simpler compared to using TinyDB

Well, it would be enough to save the dictionary to TinyDB at each modification, but you also need to consider that in case the app is uninstalled no data would remain on the device, and you would have to implement data saving on Firebase, for example.

With a dictionary, to get all the character you would just need to use the get keys block to obtain a list of all the names.
immagine

Thanks all for your input!

With a dynamic button, how do I set up so there will be one name (key) per button?
And if a new character is created a new button will be created

I don’t know if you’re managing the buttons with the RecyclerView extension, DynamicComponent or with the native dynamic components.
Anyway, if it’s DynamicComponent/native components, inside a for each you place your blocks to generate the buttons.

Example with dictionary

blocks(16)

Ill take a look! Thanks!

1 Like

okay, so i tried, but i get an error with thedynamic button.

and on the list-Character_screen.

The save seem to work, but the issue seem to be with the Dynamic button

Leaving aside the apply-to-args error that will be fixed,
this happens because the variable heroes is empty, try adding two pairs with the key as the character’s name and the value as empty.

Be careful with the ID,
since you’re using the native dynamicButton, the ID must be a different number for each component created.

You should do something like this.

Yeah I do understand that it needed to be individualized, just didn’t know how. I’ll test, thanks