List is not a list after saving

how and when should i encode and decode. right side saves, left side reads.

You can save AI2 lists to most, if not all of the available databases: tinyDB,tinyWebDB, CloudDB, Firebase, and the data can be returned as an AI2 list. If you save an AI2 list to a file, it will become a string (as you have seen), so when the data is returned you will need to convert it back into an AI2 list.

Google Sheets will directly export data in csv format, with this you need to convert the data to an AI2 list. If you use google apps scripts to interact with a google sheet, it is likely that the data can be sent and returned as stringified JSON arrays, which will need to be converted back into AI2 lists.

When you need to do the conversion will depend on what you are doing with your data. For example, you can display an AI2 list in a label. The label text is a string, the data, as a label text is no longer in a list. However the list will still be in the variable you saved the list to.

In your last image you show a list in json format (includes some values with the curly brackets { }. This data can either be converted to an AI2 list, with just square brackets [ ], or you can convert it to a dictionary and work with dictionary blocks, which are more suited to working with json data.

1 Like

i think that answers my question even though i havent processed that as an application.

my intent is to make a configuration file that i can copy as a backup and manipulate outside of AI2 if needed.

the necessity to have internet access is a deterrent for google sheets, although i do like the idea of google sheets.

i paid for the extension from Jewel and even though i paid 50 bucks for the "top option" i have not been able to get response from Jewel on how to get started building it into my blocks.

is there a way to see and access TinyDB from outside AI2? is there a way to copy and manipulate TinyDB in that way? also namespaces seems not dependable as my data is sometimes there and sometimes not, or in the wrong namespace. its likely my fault through sloppy work, but thats part of what im trying to achieve using the file. it seems more tangible from this point.

Which extension was that ? ( I see it was probably the Google Sheets one, I just released a free extension that does all this and more for free....)

No, the tinyDb is locked away inside your app, it can only be accessed from within the app itself (Android 11+)

Yes, you can export (and import) the contents of your tinyDB (there are many methods/extensions), but you have to do this (export/import) within your app.

In my experience, tinyDb and namespaces have been totally reliable. Remembering to set the correct namespace is subject to human frailty though :wink:

1 Like

once i figure out the decoding mystery, i think the text file will be reliable and lend itself to outside interaction.

is there ever a need to encode while saving?

do i need to encode parts like dictionary as i save them to a list?

i am now using variables for each piece as a troubleshooting method, but using MAKE A LIST an adding the components seems easier if there isnt a good reason not to.

Depends on what you are saving and where/how you are saving it :upside_down_face:

When you create a dictionary or a list, you are creating an object. The content of these objects is in the main made transparent by the AI2 blocks, which can cause confusion. If you spent any time working with javascript, objects are quite opaque, unless you handle them correctly.

If you create a dictionary and add data to it (either as a list or json { }, then you are adding data to that dictionary object. If you want to save a dictionary (object) as a list (object) - that AI2 understands, then you will need to use an encoding block to help with this.

For example:


image

There are other ways to do this, for more complex structures.

2 Likes

this is how i was able to combine a list of items, and dictionary into a single file and read from the file, back to a list and object(dictionary)

@TimAI2 how do you change the font for object? i read that in the original introduction but it didnt sink in

also, THANK YOU, THANK YOU, THANK YOU! your explanation fit my question very well and on point.

What am I doing wrong here?



Your blocks lack patience, and this event block: (edit with apology - ABG)
component_event

Don't try to read a file until after the O/S has finished writing to it.

@ABG

I've been fighting this since Friday, so patience not an issue
i read the reply on my cell phone so i didnt see all of it...

Im trying that now

I added that block so im confident that my issue isnt there

also ill add that the issue SEEMS to manifest only after i refresh companion. that is, as I dont close the app, the issue isnt created.

i added a global variable to see what the raw text looks like before and after encoding. it seems full before encoding, but the select list item cant accept it.

after encoding, it returns only the first segment

Here is the code sequence that is impatient:
366e0d2eaa8986e030d5b043465f9d840b1b4ac5_2_690x215

The second block is running before the saveFile data has fully arrived.

Also, clear your block comments to help distinguish new Do It results from leftovers.

2 Likes

Yes, Sir. it seems to work, better .
still debugging. I will mark this as solution as soon as i get past.

TY!

I created a button stop in the FOLLOWING step, that didnt help as it was misplaced.

that seems to help, next piece of the same puzzle

Do you have ShowListsAsJson unticked for a reason ?

i do not. ill tick it now

You are not doing anything with global temp, other than probably checking its contents at the wrong time.

Do we assume you are not getting anything in your list global NameIndex either ?

global temp is just there to provide a window into the passing of data
it seems to show that the ITEM is an empty string while the length of list is 2
Global temp should update 2 times and the last would be visible after the fact

each of the lists starts with NAME

global nameIndex would become a list of the names only for indexing the dictionaries

It remains an empty list