Special loop type for arrays & dictonaries - Why?

FrameXX

Well-known member
The next version is not yet released, but I am already translating array iteration loop.

My point here is, that I don't see reason to make a special loop type for arrays. We can just use a normal loop, count how many times loop has looped and add an condition/constraint of array/dictionary lenght (loop < [arrlen=my array name]). Because I know you always think before doing something and there is some good reason for making an extra loop type just for array/dictonaries I am not proposing you to not implement this, but just please add a magic text for array/dictionary lenght. Something like this:

[arrlen=my array name]

[dictlen=my dictionary name]
 
Last edited:

dsnz

Well-known member
it's simpler, useful, faster 😂
that's why most programming languages have a

for object in <array/container>

loop syntax

so.., we have news ? we will have arrays ?
arrays of all types ? (string, number, boolean)
and there will more actions related to arrays ?
tell us more 😂
 

FrameXX

Well-known member
it's simpler, useful, faster 😂
that's why most programming languages have a

for object in <array/container>

loop syntax

Thank you. I didn't know that.

tell us more 😂

MacroDroid will get support for arrays and dictionaries, but because we can now only see strings, there are still lot of questions to ask and you will see the result in beta. Or maybe this is a feature that needs long preparation and implementing into MacroDroid, so we will get it in version afterward. I can't really say.

This is a difference between array and dictionary

Array
Python:
cars = ["Ford", "Volvo", "BMW"]

Dictionary
Python:
car = {
  "brand": "Ford",
  "model": "Mustang",
  "year": 1964
}

arrays of all types ?

Propably yes. I hope so.
 
Last edited:

FrameXX

Well-known member
dictionaries too ? that's impressive 😊
I think you can simulate dictionary easily with 2 arrays. 1 will have key and the second values. But again this is like with the special loop type for arrays/dictionaries.
 

dsnz

Well-known member
the simulation you are thinking is poor man's dictionary and very slow also
(plus would need many lines of code to achieve and would be inconvenient to pass around)
it's unthinkable today (2022 😂)

I wish only that such new actions are not entered in visual form only
but also as code in a text (as in other programming languages)

so MD would support blocks of code in text interspersed inside macros
this would help also to shorten macros and make them more manageable
 

FrameXX

Well-known member
poor man's dictionary and very slow
Sorry, I am an amateur. I use logic and if something seems to work overall, then I use it, no matter if it's "right" or not.

I have nothing against MD implementing dictionaries or special loop type, it's just another feature on top and another option for anyone to use.
 

MacroDroidDev

Administrator
Staff member
The iterate dictionaries/arrays is mainly a convenience feature in terms of arrays. For dictionaries it's a bit more than just that as it allows you to iterate over all keys without knowing what the keys are.
 

Shaykid

New member
But I cant Iterate the [iterate_value] field.., when i create an iterate loop, it doesnt give me this value to work upon as dictionary.
 

dsnz

Well-known member
because I don't have this need like yours and I'm lazy to create an example code
can you post your macro code to examine it and see how to do what you ask ?
(or maybe discover a bug or a design issue)
 

Shaykid

New member
I found the bug, looks like when i create a new array index, if the value is dictionary, MD doesnt create the cell
Any ideas ?
 

Attachments

  • Array_Demo_(Usage)_dictionary.macro
    9.7 KB · Views: 30
  • d6af875e-5123-4e17-aaf5-f4e43316f5b1.jpeg
    d6af875e-5123-4e17-aaf5-f4e43316f5b1.jpeg
    93.5 KB · Views: 82

dsnz

Well-known member
with some fixup of the macro (maybe import problem)
I can verify that the entry for index 998 which should store a dictionary is not created !
however if entry 998 exists already then it's filled correctly with the dictionary assigned

so it's a bug for @MacroDroidDev
 

Shaykid

New member
Hi
a - I filled a bug report, thanx
b - even if entry is there, we still experience some problems
I'll waut for Dev response
Thanx a lot
 

sneike

New member
separately of course, with a second loop inside the main loop

you gotta know the structure of the dictionary and how deep it goes
Is it really possible to iterate a dictionary inside another dictionary? I'm trying creating a second loop inside the main loop but I can't iterate on the second nested level of my dictionary variable. Is there something I'm missing?
 

Endercraft

Moderator (& bug finder :D)
Is it really possible to iterate a dictionary inside another dictionary? I'm trying creating a second loop inside the main loop but I can't iterate on the second nested level of my dictionary variable. Is there something I'm missing?
You mean the magic text option doesn't appear ? If that's the case, then you need to enter these manually :
[iterator_dictionary_key] or for array [iterator_array_index]

[iterator_value]
 

sneike

New member
You mean the magic text option doesn't appear ? If that's the case, then you need to enter these manually :
[iterator_dictionary_key] or for array [iterator_array_index]

[iterator_value]
I mean that if I have an array variable of arrays, when I create the loop and select the variable to iterate, I can only select the main array variable, and not any of the arrays contained in the variable.

For example if I have an array named "array-name", and inside this variable there are 10 other arrays with 10 elements each, I can't iterate the variable array-name[first-array], but only the main array-name.

Same thing with a dictionary of dictionaries.

Every now and then it seems to work, but I can't seem to understand.

Maybe it's a bug? @MacroDroidDev

Thanks for your help
 

Endercraft

Moderator (& bug finder :D)
I mean that if I have an array variable of arrays, when I create the loop and select the variable to iterate, I can only select the main array variable, and not any of the arrays contained in the variable.

For example if I have an array named "array-name", and inside this variable there are 10 other arrays with 10 elements each, I can't iterate the variable array-name[first-array], but only the main array-name.

Same thing with a dictionary of dictionaries.

Every now and then it seems to work, but I can't seem to understand.

Maybe it's a bug? @MacroDroidDev

Thanks for your help
To me that seems more like a feature that doesn't exist yet than a bug, but I would understand that it would be difficult to implement since you would need infinite a magic text. Or maybe not.
You can make a post in Feature request.
 
Top