by lighfu
Version 1 (March 29, 2023)
Download (16 downloads)
I have some questions about the behavior of adding arrays, so I would like to leave a sample flow here.
No.1 assumes the following behavior:
① variable set) array = [1, 2, 3]
② array add) multi += array
③ array add) array += [4, 5, 6]
④ array add) multi += array
I expected the multi-array to become [[1, 2, 3], [1, 2, 3, [4, 5, 6]]].
However, in reality, it becomes [[1, 2, 3, [4, 5, 6]], [1, 2, 3, [4, 5, 6]]].
The same phenomenon occurs in No.2.
Assumption: [["hello"," "],["hello"," ",["world"]]]
Reality: [["hello"," ",["world"]],["hello"," ",["world"]]]
To achieve correct behavior when adding to an array, use variable set (array = union(array, [4, 5, 6])) for adding to the array (No.3).
This phenomenon can be replicated with Array add, set remove, Dictionary put, remove.
In my opinion, this is a bug in the structure of redirecting variables.
In Variable set, the change in variables is applied and updated correctly, but Array add, Array set, etc. do not apply changes to variables correctly, which means that the old variable is used.
For example, define an array a with a Variable set.
① Vs) a = [1,2,3] ;; a$0
In this case a$0 holds the array [1,2,3].
Let's redefine the array.
② Vs) a = [4,5,6] ;; a$1
In this case it should be a$1 that holds the array [4,5,6].
Note: Everything after ";;" indicates internal processing automatically managed by Automate. (It's imaginary.)
Vs) stands for Variable set).
Aa) stands for Array add).
As) stands for Array set).
La) stands for Log append).
in short,
① Vs) a = [1,2,3] ;; a$0 = [1,2,3]
② Vs) b = [a, a] ;; b$0 = [a$1, a$1]
③ Vs) a = [4,5,6] ;; a$1 = [4,5,6]
④ La) b ;; b$0
output > [[1,2,3], [1,2,3]]
This is normal and
① Vs) a = [1,2,3] ;; a$0 = [1,2,3]
② Vs) b = [a, a] ;; b$0 = [a$0, a$0]
③ Aa) a + [4,5,6] ;; a$0 = [1,2,3,[4,5,6]]
④ La) b ;; b$0
output > [[1,2,3,[4,5,6]], [1,2,3,[4,5,6]]]
This is strange behavior.
Maybe the Array add block doesn't apply the variable handling well, or maybe there's a problem with the finalization of the values.
(In ③, a is written to a as $0 instead of becoming $1.)
Either way, the defined variable can be rewritten using another variable.
Following this principle, the following is possible.
① Vs) a = ["hello world"] ;; a$0
② Vs) b = a ;; b$0 = a$0
③ As) a[0] = "wow" ;; a$0[0] = "wow"
④ La) b ;; b$0
output > ["wow"]
(In ③, a is written to a as $0 instead of becoming $1.)
① Vs) a = {"a":"Flying witch"} ;; a$0
② Vs) b = {"0": a, "1":a } ;; b$0 = {"0": a$0, "1":a$0 }
③ Dp) a + {"b": "Slowlife"} ;; a$0 + {"b": "Slowlife"}
④ La) b ;; b$0
output > {"0":{"a":"Flying Witch","b":"SlowLife"},"1":{"a":"Flying Witch","b":"SlowLife"}}
(In ③, a is written to a as $0 instead of becoming $1.)
* Dp) stands for Dictionary put).
Note: Automate doesn't always keep multiple values with keys like $xx for a single variable. This is just a hypothetical internal ID assigned to explain this inexplicable behavior.
v1.36.1
5 stars | 2 | |
4 stars | 1 | |
3 stars | 0 | |
2 stars | 0 | |
1 star | 0 | |
Reports | 0 |
Rate and review within the app in the Community section.