How do you make a multiple initialize global in one screen?

Im trying the multiple initialize when the screen2 is initialize it will set label1.text to get global value, and another set of label2.text to get global value2, but when I try it it only show 1 initialize global value how to fix this

Make a list

1 Like

Hello Alvin, welcome!

Define your Start Value as a List instead of text, then assign to the vars (cannot be done as initialize as per your Blocks). I assume you have images in the Start Value because the User will select them from a range.

Screen1

Screen Result

Note, before you commit to using multiple screens, it may well be easier and more efficient to use Virtual Screens instead.

When we define virtual screens, we use one 'real' App Inventor Screen (most often Screen1). Screen-sized Vertical Arrangements on it are displayed/hidden as required - they are the Virtual Screens. This is generally a better approach for multi-screen Apps, they share data without having to "pass" it between screens and it also reduces code duplication, making the App more efficient and the code easier to follow if you have to return to it at a later date.

So, instead of separate "houses", virtual screens are "rooms" of the same "house".

Important Note: Include the item type in Screen and Component names - this makes it easier to follow your code and avoids the issue of reserved words being used.

Edit:

Although I have used png files in the example above, webp files are superior - same quality, but less kilobytes.

https://www.professorcad.co.uk/appinventortips#TipsImages
https://www.professorcad.co.uk/appinventortips#TipsGui

2 Likes

super thanks I'm so new at this app, do you have yt or any video guide about that? Im more used on watching video xd than reading document

I usually don't have time for videos - They fall out of date very quickly and a good video requires a lot of editing. So - snippet code examples are the better approach.

Myself and other Power Users have dedicated App Inventor pages, hopefully you have seen mine for the tips and tricks.

Juan's website: App inventor. Examples. Tutorials. Games. Codes blocks.
TimAI2's website: METRIC RAT AI2
Taifun's website: App Inventor Tutorials | Pura Vida Apps

3 Likes

Super thanks for the links