Hi, I created an app with two TimePicker instances. The AI suggested to convert the TimePicker.AfterTimeSet code into an any-component block. There I want to set the TimePicker.Text property but I have to fill the “of component” socket and I can only find TimePicker1 or TimePicker2. From my understanding I would have to fill the socket with the generic TimePicker instance of the any-component but I can’t find it anywhere.
The "of component" parameter expects a component instance block. These both does the same job:
"any component" blocks are mostly used for setting properties for multiple components, if you only want to change property for single component, you can just use the appropriate setter block of the component.
If you want to use "any component" block in "any component" event, you can use the "component" parameter which returns the component that the event invoked for.
Ok, thanks, now I found the get(component) function in the Built-In->Variables section. That’s it.
You can also move your mouse over orange-colored parameters to directly access to parameter.
Make a Block List of the (identical type) Components to give all of them the same attribute using Any Component.
In your case, Any Component may not be appropriate, it's only two Components and I presume that the Text property will not be identical?
Thanks for the tip, alas that’s one of the few things which don’t work when using AI on an iPad or likely on any tablet. The others are editing comments and viewing the contents or deleting items from the backpack.
What do you mean with “Make a Block List”, something like this?
Though it may not have been the most appropriate solution in this case there are three things to consider. First, using a different approach the question would have come up again on the next occasion.
Second, generic code like the AI any components improves the code clarity and from my even short experience that especially important with larger projects in AI2.
Third, I prefer generic code over copying and adapting code blocks as that is prone to introduce errors in form of typos as well as changes not being applied to all places. That’s why I put text strings like database tags into constants instead of typing them into each getValue/setValue instance and this leads to another issue with AI:
Running the Code Cleanup my global variable definitions I intentionally had placed on top of the workspace partially were dispersed between the other blocks. What I’ missing is something which could be named syntactic sugar. Either the Code Cleanup function should collect code blocks with respect to their type, i.e. all global variables, event handlers, procedures together on different spaces of the workspace. Or there should be special blocks only affecting the arrangement of the top level blocks on screen, so that you could group them together unaffected by the cleanup function.
Apart from that it really is impressive what I could achieve with AI2 in just two days of coding, starting from scratch with the Framework as well as app development in general.
Yes, exactly that - especially useful if several attributes need to be set as identical for all components in the List.
That's very odd - I always have my vars at the top of the code and Cleanup has never disrupted that. That said, I always arrange my Blocks in a single column.
Me too left them that way - more or less -exactly because I feared the autumated cleanup happily would mix them if I didn’t. But I would prefer to have a column each for global vars, procedures, event handlers and anything else if I missed something. The automated cleanup could do that but I think special block grouping containers, like I mentioned in the previous post, have a strong advantage: when you extend one block the corresponding slot in the grouping container would expand automatically. That means no overlapping blocks anymore - without having to invoke the cleanup function.
This was once achieved in a student project, but in the end was not incorporated by MIT. I think code containers, where the App Developer decides which one is for what, would be very beneficial. This kind of change though requires an upheaval of the original interface code and the MIT team just don't have the time available - it is a struggle to keep up with Google's Android changes alone.
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.