Bug in removeElement

Post your questions and help other users.

Moderator: Martin

Post Reply
User avatar
bichlepa
Posts: 148
Joined: 04 Mar 2014 18:29
Location: Germany
Contact:

Bug in removeElement

Post by bichlepa » 11 Apr 2014 15:49

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.

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Bug in removeElement

Post by Martin » 12 Apr 2014 07:38

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.

User avatar
bichlepa
Posts: 148
Joined: 04 Mar 2014 18:29
Location: Germany
Contact:

Re: Bug in removeElement

Post by bichlepa » 12 Apr 2014 08:50

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.

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Bug in removeElement

Post by Martin » 12 Apr 2014 09:45

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.

User avatar
bichlepa
Posts: 148
Joined: 04 Mar 2014 18:29
Location: Germany
Contact:

Re: Bug in removeElement

Post by bichlepa » 12 Apr 2014 10:32

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.

Post Reply