Hi all,
Today I am working on a project, where I want to design an APP with 8 buttons. Each Button has to send a number or text via BT. I can do this by drag and drop a button block and set procedures for each of then one by one. I wondered if there is an easy way to do that e.g., by using lists and global variables , Is there any means to generalise this function as I need to change the button text also for each of them.
use dynamic components or recyclerlist or compcreator extensions
I would do it extension-free, with generic blocks.
Keep lookup tables mapping button components into sent text, for on and off.
Parametrize your procedure with button component.
For code samples, post draggable blocks or a small aia.
This should work (untested) using the 'Any component' blocks available in AI.
One small correction in my example is 'compare texts' = "OFF" (not "Off")
Hope it helps!
C.
This (also untested) will hopefully provide the BT Text for each of the buttons - where named Button1, Button2... to 8.
Let me know if it doesn't work!
C.
Tuesday Motivational Quotes: Each new button you press in life is a step forward keep pressing toward success this Tuesday.
The dictionary keys can't be used as buttonIDs, because they are not component blocks.
They are red text blocks.
Button component blocks would be a different color. (Green?)
Hi again. This may work better as the dictionary gets filled with the correct Runtime-button-names.
Note: The list needs to be completed in reverse button order, ie. 8 to 1
Hope this v3 helps!!
C.
I like to enumerate my button components by keeping them in a global list of their components.
This lets me use the Index In List block to go from a button component to its numerical position in the list.
This also lets me exclude other buttons that should not be included in the list for this special handling.
Yes it did work as expected by me. I tried this app and its interface worked good. It saved me from creating redundant code blocks for every button individually which seems ineffective way of doing the code. I will now have to add more functionality to this project , But for now my button functionality has been fixed. Now I will try to work on other modules of the project.
@chrisRoald @ABG Thank you for your replies and suggestions.
Hi as your supposed blocks worked fine. I made extra efforts to extend this code . I added a Bluetooth Button to enable BT and select devices and save address of last connected device. But when I press BT button, It does the same operation as other 8 buttons do (e.g., its image is changed ) and now I am stuck here.
In the generic button click event there has to be code to test if the button already has a click event handler, to head off conflicts.
There is a generic event parameter for that: notAlreadyHandled.
Wrap the generic code with an
If notAlreadyHandled then
Do the generic stuff
block.
Some people use an Is component in List test in the generic event.
There is nothing you can do in the specific button component event to control this.
Sample app:
Hi Younus, ABG was right all along... use the dictionary list as shown here, and your BT button will be left alone.
ABG's solution correctly suggests to use the actual (green) button block - in the dictionary - for each of the buttons you want to change colour and text. At runtime each button block carries the actual component name of the button, which can then be searched ('lookup') in the dictionary. Thanks ABG for this.
Good luck.
C.
(post deleted by author)