Hi
How can I add and remove value in map (script).
Give me one example.
Thanks from record4
Map in script
Moderator: Martin
Map in script
No.1 Automation app in play store Automagic Premium
Samsung Galaxy j2 non rooted.
Android 5.1.1
Samsung Galaxy j2 non rooted.
Android 5.1.1
- digitalstone
- Posts: 342
- Joined: 21 Oct 2017 12:36
- Location: The Netherlands
Re: Map in script
Just removing the value itself and letting the variable intact
Removing the variable entirely would be
Code: Select all
variable=""
Code: Select all
removeVariable(variablename)
Phone: LG Nexus 5X (rooted vanilla Android 7.1.2)
Re: Map in script
Hi digitalstone
Map means functions in script "new map, new map from values, is empty, copy map, length,add map entry, remove map entry etc".
I am in bit confusion about these functions.
Thanks from record4
Map means functions in script "new map, new map from values, is empty, copy map, length,add map entry, remove map entry etc".
I am in bit confusion about these functions.
Thanks from record4
No.1 Automation app in play store Automagic Premium
Samsung Galaxy j2 non rooted.
Android 5.1.1
Samsung Galaxy j2 non rooted.
Android 5.1.1
- digitalstone
- Posts: 342
- Joined: 21 Oct 2017 12:36
- Location: The Netherlands
Re: Map in script
Well, what do you want to do exactly? I may be wrong, but i get the idea you want to memorize every single function. This will be inefficient.
It all depends on what you're making. Then you decide what type of step/function you need for each obstacle you face, and then you search for that particular function. And over time you will learn those functions as a positive side-effect.
But for now, just check and read the description beneath the functionname within the script-help page.
I'll explain the first 2 since i don't have much time right now, but you'll get the general idea:
"new map" is to create a new map variable
"is empty" is to check if the map variable is without any value (true or false)
It all depends on what you're making. Then you decide what type of step/function you need for each obstacle you face, and then you search for that particular function. And over time you will learn those functions as a positive side-effect.
But for now, just check and read the description beneath the functionname within the script-help page.
I'll explain the first 2 since i don't have much time right now, but you'll get the general idea:
"new map" is to create a new map variable
Code: Select all
rafi_map = newMap()
Code: Select all
isEmpty(rafi_map)
Phone: LG Nexus 5X (rooted vanilla Android 7.1.2)
Re: Map in script
To create a map object, you can use newMap() for blank map, or newMapFromValues(key, value) to define the map with keys and values directly.
To add the map entry, you can use addMapEntry() or immediately assign the map keys to it.
To remove an entry from the map, use removeMapEntry.
length() and isEmpty() should be quite clear already, to check the length and to check if it is empty (no entry).
While copyMap() is used to flat copy. The difference with assigning directly is the copyMap() create new object instead of assigning it to the same pointer. So changes to existing map object won't change the new copied map.
after removal, c and d now are empty, even though you only remove c. but e retain the key-value ("state", "on"), since it is new copy
Code: Select all
a = newMap();
b = newMapFromValues("apple", 11);
Code: Select all
addMapEntry(b, "banana", 22); //add a new key "banana" with value 22
a["state"] = "on"; //add a new key "state" with value "on"
Code: Select all
removeMapEntry(b, "apple"); //remove key "apple" along with its value 11
While copyMap() is used to flat copy. The difference with assigning directly is the copyMap() create new object instead of assigning it to the same pointer. So changes to existing map object won't change the new copied map.
Code: Select all
c = newMapFromValues("state", "on"); //create new Map c with key-value ("state", "on")
d = c; //assign d to point to object c, so both c and d point to map with key-value ("state", "on")
e = copyMap(c); //create a new map copy of c, e is separate map object
removeMapEntry(c, "state");
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.