Need help in using two dictionaries accessed by single Button

Hi, I am here with a new problem. I happened to make additional changes to my previous project . I want to send two different texts or numbers using a single any button component. I already have a dictionary to send values but now I added another dictionary with other set of values. I want these values to be sent via Bluetooth after checking button text. so I have parallel data that will be sent conditionally. Moreover, I want to know whether I could use Extended ASCII characters on my button. Any ideas?

dictionaries

buttons
image

I keep my color constants in named global variable constants, to avoid the possibility of introducing slightly different colors into the code.

I got burnt by that once.

AI2 uses UTF8, so extended characters should work wherever you use text.

I see from your dictionary content that the text codes are unique across buttons, so the two dictionaries could be combined into a single dictionary mapping each possible button text into its opposite text. The combined dictionary would have twice the number of pairs, to cover both directions.

The new procedure would be...

Look up the button Text in the combined dictionary.

If not found, do nothing,

Else replace the button text with the lookup value.

You might be able to do the same with colors, though I am not sure those fit into dictionary keys. The list lookup in pairs block is more forgiving.

Dear @younusAI,
in addition to all that @ABG has already said, you can try in another way, by using lists (instead of dictionaries). The annexed .aia shows how (tested on my Lenovo pad), and here below the related blocks. Of course you have to adapt the algorithm to your needs. Best wishes.

@ABG Here I want to send 1 if button text is RED and 'a' if the button text is Green . So i do not need to store any colours into the dictionary as i just need to check colours in a condition block. My function is simple when colour is red send a 1 and when it is not red send 'a'. My question is how could I get values conditionally from dictionary , If I combine them into one.

Dear @younusAI, my algorithm using lists does exacly what you need.
Since dictionaries do not feature a method that returns the "pointer" to the element satisfying the key matching, but the lists on the opposite do, I've used lists.
Give it a sight.
.
MultiListExample.aia (4.0 KB)

Here's a filtered table version:

Blocks:

Source:
button_lookups.aia (3.9 KB)

Designer:
Designer

Sample run:
Sample run

(I left out setting initial button colors at startup. The opposite color procedure is self-correcting.)

P.S. I should have renamed those color constants to ON_COLOR and OFF_COLOR, but I was not sure which was which.

yes that was great working fine. One thing I noted using lists is that we can not use an independent button while playing with lists and that is why I was looking to perform the functionality of independent button with lists to check whether I could change button image along with colour or not if I add more block in a list row which I did but got this error:

image

changing image of a button gives it a 3D feel while pressing the button.

You need a separate click event for the master button, since it doesn't fit into the scheme of the generic button click event.

1 Like