Alright, that's quite the trigger. So what is your goal here because if you're using Hashtables then you shouldn't need to even have For Loops. You can just Load exactly what you need and do with it as you please.
Some random notes:
- Hashtable Arrays may be unnecessary. You can probably get away with 1 Hashtable per category. The Hashtable limit is 255.
- You're using "AND - All Conditions are True" for no reason. By default all conditions must be true.
- Custom script: exitwhen true <-- Does this work?
Is there an easier way to find a certain unit within a hashtable? Frankly I might have been doing it wrong since I don't know any better. I use for loops because I need to find every dependency on a building, since I made my map with a "Tributary" system, if you will.
For example, there's the primary great halls, who serve as the city center and are built by colonists trained by great halls or spawned at the start of the game.
The secondary great halls act as districts and allow for the city's expansion. They can only be built by primary Great Halls.
The production buildings and houses (I've only worked on War Mills so far) can be built by either Primary Great Halls or Secondary Great Halls, and here's where the dependency system kicks in.
If I build a War Mill, I need the game to know it's a dependency of Primary Great Hall 2, let's say, that would be the Great Hall stored in the handle 2 of KeyGreatHallPrime (The integer variable is 1, I've chosen to have it like this in case I want to change the key for it to be easier and to not forget what key I used for what subset of buildings/units) in the Buildings Hashtable. But, if it's built by a secondary great hall, then the dependency goes as follow -> The War Mill belongs to the Secondary Great Hall which belong to the Primary Great Hall, and I want the game to be able to tell that. Which is why it goes through all these loops, maybe necessarily in some cases, because for example if the Primary Great Hall gets destroyed, or gets upgraded, etc., the game will need to find all dependencies and do something with them.
If there's a better way of doing this I would really like to know because it's terribly inefficient, but I can't think of another way to do this.
As for the AND thing yeah, I kind of went overboard, I just used it because it makes the conditions stand out a bit more from the rest of the text. The custom script does work, it breaks out of the most recent loop.
From looking at your code, it does seem possible that you would reach the OP limit. IIRC you could do a few hundred thousand hashtable lookups before the OP limit was reached, but since you're using GUI that means you're going to have a lot of additional inefficiencies from having to make superfluous function calls. So only being able to run your loop a couple of tens of thousands of times seems reasonable.
What I would recommend doing is completely redesigning your trigger. Could you explain what your storing in the hashtables? It seems like you're storing a list of units. Also, it seems like you're storing a String and a Unit in the same key? As far as I'm aware you're not able to store two values in the same key of a hashtable, even if they are of different types.
What is this trigger supposed to be doing? What I can gather is:
- when a primary building dies, destroy all secondary buildings and war mills that are connected to it
- when a secondary building dies, destroy all war mills that are connected to it
- I'm not sure what's supposed to happen when a war mill dies?
- I'm not sure what's being stored in key (Integer X) * -1? Like in the following line:
-
Remove (Load ((Integer A) x -1) of KeyGreatHallPrime in DatabaseBuilding[TempPlayerNr]) from the game
Yeah it works. Basically the same as a "break" statement in actual programming languages.
I'm storing units that depend on other units, the string is built out of 3 identifiers (First three digit represents the primary building, next three represent the secondary dependency and the last three the tertiary dependency), if it's a Primary Great Hall like I explained in the upper novella (lol), only the first three digits are used and the rest are 0s, if it's a Secondary Great Hall or production building/house built directly by the Primary Great Hall the first 6 digits will be used, and the last three will be 0s and if it's a production building or house built by the Secondary Great Hall it will use all digits. The identifiers are part of the dependency system I've developed. You can store an integer, a real, a boolean a string and a handle on the same spot of a hashtable without them conflicting, the conflict comes when you try to save another handle, be it unit, doodad, special effect, etc. since they all use the same storage, but the rest can be saved safely.
As for what the trigger does you're partially correct. Secondary buildings and war mills get destroyed only if they have the "Set" ability which means they haven't officially been built yet and resources used. I'm using a system that allows you to rotate the buildings first before placing them and using the resources, as an aesthetic choice. Building without the "Set" ability will cancel all production and become rescueable if War mills in this case, or gain the ability to become a new Primary Building/City Center if they're a Secondary Great Hall. Same for War Mills linked to Secondary Great Halls.
What's stored in the Integer x -1 is a special unit I use to imitate the pathing the building is supposed to have. Since you can't rotate buildings, I had to turn the building you actually interact with into a unit. There's also another benefit to this, if an immovable unit tries to use a tiny build ability, the game allows you to choose to build over the casting unit when you hover the placing model, and the immovable unit automatically gets moved to the side so the tiny unit building gets built. if I use these "Foundation" units that act as actual buildings, but have no model, the game will see they block pathing and are not the casting unit and thus won't allow you to build over the casting unit.