Create a structure or class

Hello,

I'm looking to create a structure or class to create a variable with several parameters.
For example :

struct MyStruct {
    int value: 0
    string text: "My text"
    bool verif: false
}

or

class MyClass {
    int value: 0
    string text: "My text"
    bool verif: false
}

label1.text = MyStruct.text OR label1.text = MyClass.text
MyStruct.verif = true OR MyClass.verif = true

With lists, I don't have the names of the values. Just the index numbers.
As for the dictionary, I don't like using the "Not found" variable all the time.

If anyone has another solution, I'd be very grateful.

or

image

This is not practical for reading a simple value or writing a value.
A loop to read or write a value is not very optimised.
All these blocks seem too complicated and overload the code.

If you make sure the key is in the dictionary, this "Not found" will never returned.

There is no such option in AppInventor. You can use Java and AndroidStudio. You can also add such a function in the open source AppInventor. AppInventor will provide the usual global and local variables, dictionaries and lists.
If you want to create a thousand instances of such dictionaries, of course there will be a lot of blocks and they will burden the project, but this means that there is something wrong with your code.

I found this solution.
A global variable comprising 3 different variables (Int, String and Boolean)
3 Get and Set procedures and a global procedure.
That's not bad, is it ?

1 Like

it looks like you are making simple things complicated.

Can you tell me more?

you made 6 procedures just to get and set data of a list, and more if blocks to decide which one to call.

always remember KISS principles.

Yes, but at least they are easy to call.

Was this not "easier" ?

image

In your case, the easiest one is a dictionary.

blocks - 2024-03-17T164736.155


1 Like