Page 1 of 1

Bug in removeElement

Posted: 11 Apr 2014 15:49
by bichlepa
There is a bug in removeElement() that caused me quite a headache :( .

See that flow:
It does: Create a list "global_temp_list" with three entries and copy it into "liste".
Then it should: Detete an entry from "liste".
It does instead: Delete the entry from "global_temp_list" and store the (should have been) deleted entry in "liste".

http://automagic4android.com/flow.php?i ... 543aedfc85

Now I use removeElementValue() insted.

Re: Bug in removeElement

Posted: 12 Apr 2014 07:38
by Martin
This is not a bug but the expected behavior. Assigning a list to a global variable does not copy the list, both variables point to the same list. Removing an element affects both variables.
There's also a short description in the help page about this (at the end of section Variables - Global: Variables are references to values (like a pointer)...).
http://automagic4android.com/en/help/co ... ion_script
removeElementValue() should work the same (should also affect both variables).

There is a new function copyList to create a flat copy of the list for such purposes in the next version of Automagic. For now (version 1.21) you have to loop and copy the list on your own.

Re: Bug in removeElement

Posted: 12 Apr 2014 08:50
by bichlepa
Hmmm, I didn't mention that yet. But on my test flow "removeElement()" shows a different behaviour.
Please try out my uploaded test flow.

My test flow shows two debug dialogs. One after creation of lists and another after removeElement(liste,0).
As you wrote, it removes the value from "global_temp_list". But "liste" is not a list anymore, it now contains the variable I wanted to delete!

And an other strange bahaviour:
When the first debug dialog appears and I choose variable "global_temp_list", then choose "Change value" and then choose OK. If I now continue executing flow, no value is removed from "global_temp_list" but "liste" still contains the variable that should have been deleted.

Re: Bug in removeElement

Posted: 12 Apr 2014 09:45
by Martin
Function removeElement returns the removed object and not the list.
You can change your script from:
liste = removeElement(liste, 0);
to
removeElement(liste, 0);
or when you want to do something with the removed object:
removed_object = removeElement(liste, 0);

The UI-editor to edit a list has to create a copy of the list, otherwise the dialog could not offer a Cancel-button when the underlying list is directly modified.

Re: Bug in removeElement

Posted: 12 Apr 2014 10:32
by bichlepa
Oh, my fault. I did not read the function description carefully enough. :oops:
It's a little bit confusing because other functions like addElement and removeElementValue do return the same list.