Documentation on Key:Value pair nested lists

Do not enable this file, this is simply to document how you can access nested lists and how to generate key lists from a key:value pair.
This commit is contained in:
Sharkmare
2023-03-08 11:53:45 +01:00
committed by GitHub
parent ba25f3c417
commit 3a49fc2ea2
+27
View File
@@ -0,0 +1,27 @@
/*
Nested lists are lists within lists, now this was probably obvious, i wouldnt waste your time with this.
What we are going to be talking about is Nested lists with key value pairs and how to access them as well as generate key lists
These are incrdeibly nice for merging multiple lists with a similiar purpose. this example here will write a fake implementation to unify the Robot_module list.
*/
/var/list/nested_robots_example = list( "Normal" = list( "Honk-Hound" = /obj/item/weapon/robot_module/robot/clerical/honkborg,
),
"Whitelisted" = list( "Unity-Hound" = /obj/item/weapon/robot_module/robot/chound,
),
"AI" = list( "Explore-Hound" = /obj/item/weapon/robot_module/robot/exploration,
)
)
//Now once we define the above list we can access it as follows
//Access the normal robots list
//nested_robots_example["Normal"]
//Access a specific type inside the list
//nested_robots_example["Normal"]["Honk-Hound"]
//Generate a list of the keys inside the normal list (so we can fill a UI with them)
/proc/list_robots(var/type) //Type here is either "Normal" , "Whitelisted", or "AI"
var/list/nested_robots_keys = list()
for(var/element in nested_robots_example[type])
nested_robots_keys |= nested_robots_example[type][element] //This returns the key from our not nested list at the lowest level //Thank you BM.