简体   繁体   English

如何避免多次写入相同的块 | 麻省理工学院应用发明家

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

In my app I have 50 Horizontal Arrangements.在我的应用程序中,我有 50 个水平排列。 (named row1, row2, row3 etc) (命名为 row1、row2、row3 等)

The user enters a number between 1-50 in a text field.用户在文本字段中输入 1-50 之间的数字。

Based on this number, the corresponding Horizontal Arrangement is altered (eg: the user enters 28, so do something to row28).基于这个数字,相应的水平排列被改变(例如:用户输入28,所以对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?与其编写块来处理每 1-50 个场景(它们都是相同的,只是名称必须更改),有没有办法将用户输入和 go 带到该行? Something like:就像是:

-user enters 28, so set row[28] to visible -user 输入 28,因此将 row[28] 设置为可见

...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.当您构建块时,似乎您必须 select 每个特定行(例如 row42),而不是有一个带有占位符的通用代码块(例如行),可以在应用程序运行时添加数字(例如 42) .

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.请查看以下线程以减少块的数量,并在 App Inventor 中使用块进行编码时学习一些最佳实践。 :) https://community.kodular.io/t/using-blocks-in-another-way/15752?u=shreyash :) https://community.kodular.io/t/using-blocks-in-another-way/15752?u=shreyash

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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