How do I use variable values as component names in blocks

image
image

As you can see on the first image, these are all the current scripts for Screen2.
The second image is my trial to use the block get (global currentLabelToFill) instead of the p1s1 value in the green block. Is there any way to do this?

Won't work. AI2 sets component "names" at runtime (find the component block at the bottom of the palette for a component). There is a possibility that a component name block will be forthcoming in a future update of AI2 though

That said, it is not really clear what you are hoping to achieve?

As @TIMAI2 said, it is not possible to get component from name (unless you use some related extension like Dynamic Components which uses ID system).
But there is a workaround, you can instead try to save component as variable and use it when needed with the help of Any component blocks.

If you are putting numbers in names, that means it is time for you to learn to work with lists.

image

I, at first, used a join block, but then, after @ABG's post, realized I have to use a make a list block. However, this caused an error inside the app. The error is Property setter was expecting a com.google.appinventor.components.runtime.Label but got a String instead. How to prevent this? This is the script that fills the label:

image
txbPoints - point textbox

Looks like you didn't understand what was advised earlier in the topic. You cannot access components by building a strong of their name. You need to use the component block.

Which means I do need to use the Dynamic Components extension, as @vknow360 has specified here?

That is one way, the other is, as previously indicated, to make a list of the components you might want to change, then select the required item on the list to change it using the anyComponent block. You could make a list of lists whereby you have a text indentifer and the component which would then allow you to do what you are doing, but with lists.

an example of this method you can find here

How to work with the advanced features

A Multiple Choice Quiz: How to work with the advanced features

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by icon24 Taifun.

Here are some sample project docs to read to see how to use lists of component blocks to address them by index ...

Thanks. However, I have a project with a lot of these labels.


Here is how all of them relate to the names of the labels:

The app's purpose is to calculate scores for Scrabble without the need for pen and paper.

The area surrounded in red shows what labels I'm talking about. Their names follow a specific format: pCsR, where:
p and s are parts of the name of the label,
C is the column number, starting at 1 on the left,
R is the row number, starting at 1 on the top.

As such, the label p1s1 will be filled first, then p2s1, p3s1 etc.

After I made the list, I made this script:
image

I will test the program's resulting APK on my phone and will post the result here.

Here is a 2 dimensional cell based app with description,
if you want samples ...

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.