{
"$type": "site.standard.document",
"bskyPostRef": {
"cid": "bafyreicjq2b4fbkm5pjr2wmn5njtg43ifcf3dsjqdimhiy4jv4snymet4a",
"uri": "at://did:plc:4n6wgsqsqm6q2hjncgwmreey/app.bsky.feed.post/3mmjm44nwc2m2"
},
"path": "/post/50847768",
"publishedAt": "2026-05-23T12:34:59.000Z",
"site": "https://programming.dev",
"tags": [
"Learn Programming",
"Fizz",
"learn_programming",
"1 comments"
],
"textContent": "submitted by Fizz to learn_programming\n2 points | 1 comments\n\nI want to preface this by saying that I think I got cooked by AI here.\n\nI have a game where I am working on a job system. The job system has a job objects which I need to put into a data structure that can be searched via id, location, or work type. At first I was building with the mindset of “do whatever to solve this problem and make it work” but it became very hard to implement new features because I would break everything. So I started trying to think ahead and design ways of doing things that would handle all the different jobs and things.\n\nAt first I put all jobs into an array and iterated through. Then I learned about dictionaries and started using them for way to many things and so i updated my job queue to be a dictionary with the Key as ID > JobObj\n\nThen I decided to plan out the job system before writing anything and “do it properly”. I decided I needed to upgrade the data structure holding jobs because its a core part of the game and will be heavily interacted with. But I realized I only know array, dictionary and database, so I asked AI what data structure I should use and it suggested a nested dictionary.\n\nNow im using multiple dictionaries but im really hating it. Its hard for me to work with and conceptually im not sure I can visualize how its even working.\n\nHow I am thinking about it is there is multiple layers of keys, 1st layer is work types, then once I find the work type it points to a dictionary of region IDs and that points to an array of jobs in the region.\n\nJob def is work type like Planting Region id: the map is broken down into region IDs so i dont have to check every tile and can limit seaching\n\n\n #python\n var job_pool: Dictionary = {}\n\n func register(designation: DesignationObj) -> void:\n \tvar job_def = designation.job\n \tvar region_id = designation.region_id\n \tif not job_pool.has(job_def):\n \t\tjob_pool[job_def] = {}\n \tif not job_pool[job_def].has(region_id):\n \t\tjob_pool[job_def][region_id] = []\n \tjob_pool[job_def][region_id].append(designation)\n\n\nHere is how I am picturing it in my head.\n\n\n var job_pool {\n \t\"plants\": {\n \t\t\"1\": {\n \t\t\t\"job1\"\n \t\t\t\"job2\"\n \t\t}\n \t\t\"2\": {\n \t\t\t\"job3\"\n \t\t}\n \t}\n \t\"mining\": {\n \t\t\"1\": {\n \t\t\t\"job4\"\n \t\t\t\"job5\"\n \t\t}\n \t}\n \t\"hunting\": {\n \t\t\"5\":{\n \t\t\t\"job12\"\n \t\t}\n \t}\n }\n\n\nBut now I want to add ID look up into this im stuck and im thinking the entire structure does not work for what it needs to do.",
"title": "Help suggest a data structure to hold objects so I can quickly look for the object by Keys"
}