Using TinyDB and any component in virtual screens

Hello everybody and especially to @TIMAI2 , who is always willing to help me.

I have a problem with the use of virtual screens and Tiny Db. Specifically the issue is in this block:

which gives me the following error:

It looks like I can't indicate the component as a string, but I have no idea how to do it any other way. Even entering the name of the vertical array "Mission1", it doesn't even let me join the block.

Everything comes because I have made a FOR loop so that depending on the values ​​of the database it shows some arrangements or others depending on the value of the database itself which I initiatite in SCREEN1:

image

In general, I usually have problems with some blocks and I only find trial-error solutions because I am not able to find detailed information about the elements supported in some blocks. Is there somewhere with detailed documentation?

Excuse my ignorance, I searched the forum and found nothing.

Thanks in advance.

Don't use a String "Mision", use the name of the VerticalArrengement.
In indexes, it is better to use numbers from Math.

You can't store components in TinyDB and expect to find them alive across runs of the app.

Do not use blank text as a TinyDB default for a list.

For naming components, use a dictionary with alpha keys and components as values.

Thanks Juan Antonio

I forgot to mention that the names of the vertical arrays match what is stored in the database, of course:

image

I have redesigned and simplified the code but it still doesn't work, same error:

image

see this.

Hello @ABG Thanks for replying.

I have erased black text for the list in TinyDB but this is not the problem.

Please, could you explain clelarly how to define a dictionary as you mentinioned. I thought that by defining the TinyDB like this, I was doing something similar to a dictionary

image

Take into account that the names of the vertical arrangements are the same as the Tiny DB:

image

I have designed a simplified code, and it still does not work:

image

I appreciate your help.

Thanks @Kevinkun

I don't understand why I can't do this. So, what is the utility of using this kind of block if you can only enter de exactly name of the component? I have seen the examples above, and it give me this idea.

image

Sorry for my ignorance.

Could you give another way to solve this situation: switch on and off Vertical Arrangement in order simulate changing screens

Thanks in advance

why you need to store them in tinyDB? for use of next time opening app?

You can make a list including all component(not its name, but the block of the last one in the layout drawer)

Then save its index in the tinyDB, then retrieve the layout according to its index.

Thans @Kevinkun

I need to store the name of some vertical arrangements becasuse they include other components that compose the the differents stages of a game (that I want to appear in the same screen, not at same time, in order to simply the code)

Additionally I have anther parallel screen with a map of the game. The gamer must be able to return to the main game screen with the same components. Thats the reason I have to store in TinyDB the state of visibility of these vertical arrangements: in order to control their visualitation.

Could you explain the block to get the index of a component?

Thanks again.

you mean virtual screen?then set the visible arrangement to a variable will be ok.

Yeah, virtual screen [mod edit personal info removed] what I want

Sorry I don't understand anything you say.

The problem is that I need to go to a parallel screen (map screen), so I need to use Tiny DB, because variables desapear between screens.

Thanks

is it possbile get the vertical arrangement index?

Here are two sample apps where components are kept in dictionaries that assign them names for storage:

Thanks for the clue

I have just discovered that if I store the index of the vertical arrangement in tiny db and in another moment get the value and use in this block, I get the mentioned error

image

On the other hand If I make a simple list storing the intex of the vertical arrangements:

image

It works pefectly:

But, as said, I can't store the vertical arrangement's indexes in Tiny DB.

Maybe this is related with the fact that storing in DB the data is converted in a string. So the question is to know what kind of data is spected in "COMPONENT" parámeter in this block,

image

Thanks in advance

1845e6959b186e7677d3905e46109e274b3b1467_2_690x254

Thanks @ABG , but he blocks marked by you works perfectly.

The tynyDB is initialited as a list of list as follow:

image

The issue is with COMPONENT parámeter, which curiously does not work with a stored value in TinyDB

I believe you have been given the answer about five times now, but not managed to apply it to your project.

See if this simple aia project helps to explain what you need to do in order to save the index of a VA to the tinydb

SaveVAOpen.aia (2.7 KB)

1 Like

Thanks Meritcat @TIMAI2 , finally you have explained really well. I didn't understand what other users say to me...

I have no words to thank you for your help. I have wasted a lot of Sunday's hours.

Your solution is really simple and smart: only storing the index of the visible arragement in TinyDB

In any case, I'm curious why storing the list of arrays in a list located in the database didn't work.

However, I am somewhat annoyed with the inflexibility of appinventor: It is true that my level of programming is very basic, but I usually solve problems by writing pseudocode that I later have a hard time bringing to APP INVENTOR because I feel that it has some absurd limitations that lead me to problems whose solution are "video game cheats".

Thanks again

Components like vertical arrangements are created at runtime, when the app initialises, and each component is given a unique name. This unique name can be used in that session of the app, but next time you run the app the components are initialised again with new unique names. Therefore if you attempt to store one of these unique names in a tinydb, it will not exist in the app the next time you run it.

Also, you cannot store strings of component names and expect them to return a component.

1 Like

Hello again

I understand what you're saying, but not completely:

In my last trials, what I have saved in the database, is the same that you done in "vaList" : the content of the block of the arrangement that gave me its block as a result: something like "com.google.appinventor.components.runtime.VerticalArrangement@ xxxxxx"

Where xxxx is what changes at every arrangement. So, theorically it should work, becasuse I stored, as you, the unique session name in a list every time the screen initializes

Maybe when it is stored in TinyDB the coding change to a text (string) or something like that (maybe xxxxx is hexadecimal)

Kind regards and I'll read you tomorrow, I go to bed