Selection dialog, sparse array, incorrect index

Kr99

New member
I have a macro where I am checking off items in the list and removing them from an array. This means that I

This means that I always have a sparse array such as with indexes 0, 1, 3, 5, 8, 10, ...

The selection dialog tells me the correct text that I selected, but not the correct array index. It has its own array index without skipping numbers. So if I selected item 5 in my example above, the selection dialog would say that I picked 3.

This becomes problematic when I want to remove an item by array index. Or if I want to modify an item by its index. In fact, it's rather hard to do anything without the correct index.

Basically, the "Save selected index" option is broken if any array is not perfectly ordered from 0.

Either macrodroid should change the arrays so that removing an element will re-index the items (no gaps in numbering), or macrodroid should change the selection dialog to return the correct index.

If you have any suggested workarounds let me know.

Thanks!
 

Attachments

  • Screenshot_20230614-082038.png
    Screenshot_20230614-082038.png
    171 KB · Views: 6

RSF

Well-known member
One workaround would be to create an Action Block to map the dialog selection # to the array index. See attached for sample action block, and a macro demonstrating its use.

An alternative would be an Action Block that takes an array and compresses it (i.e. remove empty entries). You'd have to be careful not to have any logic that assumes the indices didn't change over time, though, of course.

MacroDroid arrays' ability to have non-consecutive indices can come in handy, sometimes...
 

Attachments

  • Get_sparse_array's_true_index.ablock
    6.9 KB · Views: 1
  • Sparse_array_test.macro
    10.6 KB · Views: 1
Top