简体   繁体   中英

How to avoid writing the same blocks multipe times | MIT App Inventor

In my app I have 50 Horizontal Arrangements. (named row1, row2, row3 etc)

The user enters a number between 1-50 in a text field.

Based on this number, the corresponding Horizontal Arrangement is altered (eg: the user enters 28, so do something to row28).

Rather than write blocks to handle every 1-50 scenario (they are all the same, just the name would have to change), is there a way to take the user input and go to that row? Something like:

-user enters 28, so set row[28] to visible

...so [] would be a placeholder listening for whatever number is entered by the user.

Is this possible? It seems as though you have to select each specific row (eg row42) when you are building the blocks, rather than have a generic code block (eg row) with a placeholder which can add the number (eg 42) in as the app runs.

Please take a look at the below thread to reduce the number of blocks as well as to learn some best practices while coding with blocks in App Inventor. :) https://community.kodular.io/t/using-blocks-in-another-way/15752?u=shreyash

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM