Dictionary/Array contain

OscariBot

Active member
This sound so simply but i can't really get it working....
I want to use the if dictionary contain (x) KEY then do (Y)... But i can't seems to figure it out like other variables.

Do i have to search the dictionary/array one by one for this key?

there are over 50 entries🤦‍♀️
 

RSF

Well-known member
You can use the syntax of:
{lv=dictionary_name[{lv=key_to_search_for}]}

It'll return the value of the value associated with the key, if the key exists in the dictionary, or "{lv=dictionary_name[keyvalue]}" as a string. You can test that value as shown here:
Screenshot 2022-12-11 9.17.16 PM.png

A nice MacroDroid enhancement would be a "if (x exists in set)" action like JavaScript's has function for sets
 
Last edited:

OscariBot

Active member
thanks for responding...

but actually that's not what i wanted... i was thinking there could b a way of searching d whole dictionary at once instead of searching one entry at a time. but after considering d behavior of a dictionary it actually seems impossible to view all entry at once... it must b key by key.
 

OscariBot

Active member
but i came up with an idea... i first set a string variable ''stv'' with d dictionary content, then i apply the IF STV CONTAIN ''search text'' .
not a good way but it help.
 

Endercraft

Moderator (& bug finder :D)
but i came up with an idea... i first set a string variable ''stv'' with d dictionary content, then i apply the IF STV CONTAIN ''search text'' .
not a good way but it help.
I used this method in a macro with the index to find right before the value (and using text manipulation), like this : ,[index][value],[index][value],[index][value],
The goal is to find the index without iterating the array (then deleting that index).
 

OscariBot

Active member
GOOD IDEA...
But this seem to work only on a stable entry i.e exact 10 entry. when a new entry is added to d dict., u hv to modify ur text manipulation to accommodate d entry 11 etc
 

Endercraft

Moderator (& bug finder :D)
GOOD IDEA...
But this seem to work only on a stable entry i.e exact 10 entry. when a new entry is added to d dict., u hv to modify ur text manipulation to accommodate d entry 11 etc
that's why in my text manipulation to get the index I use d\+ (or d\{1,}).
 

OscariBot

Active member
that's why in my text manipulation to get the index I use d\+ (or d\{1,}).
pls can you show how you use it (that's why in my text manipulation to get the index I use d\+ (or d\{1,})).
because am still trying to replace your earlier idea with this. no luck.
 

DonDemon

Member
You can use the syntax of:
{lv=dictionary_name[{lv=key_to_search_for}]}

It'll return the value of the value associated with the key, if the key exists in the dictionary, or "{lv=dictionary_name[keyvalue]}" as a string. You can test that value as shown here:
View attachment 4079

A nice MacroDroid enhancement would be a "if (x exists in set)" action like JavaScript's has function for sets
What phone was the screenshot taken from? 😮
 

RSF

Well-known member
What phone was the screenshot taken from?
Not a phone, technically -- a Chromebook. I use that to create most macros for screenshots on this forum, since it has a full-size keyboard, bigger screen, mouse, etc. etc. Much faster to type, than on an actual phone.
The MacroDroid app works just fine for most actions when running within Chromebooks' Android scheme (any string or variable manipulation, HTTP requests, etc.), though not for anything related to system settings or communications -- although one can still type all that in faster than on a phone, you can only test it out on a phone.
 
Top