I have a TinyDB and in each tag of the TinyDB I have a list. Each list has 3 items, each indexed as 1, 2 and 3. I want to change the 3rd item, index 3. So I have done the following
So I want to now save the change in the TinyDB and have added a storeValue command as follows.
I figured out how to get the valuetoStore variable. As follows.
I had done this before, and thought it wrong because it still doesn't change the 3rd item in the list. But I've added a notifier to look at it and it's correct. So the "replace list item" isn't working how I thought it should. It isn't replacing the 3rd item with an "n."
Any ideas? Thanks.
Your second try is almost correct. The only thing is, you should use the replace list item
block together with the local variable name
instead of retrieving the value again from TinyDB
.
So what is the difference to your "solution"?
Currently you assign the list to a local variable name
. Then you use the replace list item
block together with a list, you can't store somewhere (you are loading the list again from TinyDB
). And in the end you store variable name
(which doesn't have been modified at all) in TinyDB
. Therefore the solution is to use the replace list item
block together with the local variable name
instead of retrieving the value again from TinyDB
. Btw. a better name for the local variable name
would be list
.
Further tips
Also in the definition of the local variable name
you should add a block, e.g. an empty string
or 0
And if you want simplify a little bit, you can move the definition of the local variable name
inside the for each
loop. And alternatively of using the for each number
loop, for list it's easier to use the for each item in list
loop, see also the documentation. The list in your case is TinyDB1.GetTags
.
As already said in the forum, generally I would use a list of lists and store it in only one tag in TinyDB
How to work with Lists by Saj
How to work with Lists and Lists of lists (pdf) by appinventor.org