Strange issue

Hambil

Emperor
Joined
Oct 16, 2006
Messages
1,100
Okay, so I have this little snippet of code all nasty and narly. I loop through the players, and inside that I loop through every city of that player.

I'm checking to see (in my tech tooltip mod) if a wonder has been built already; so I know to display it's button or not.

The issue is, it works everywhere but the tech tree (See screen shots - Great Library).

If I comment out the code that does the finally placement of the button, they all disappear so I know that the code in Tech Tree is being called, it's just giving a different result in one case than in two others.

This leaves me to believe perhaps there is some sort of initialization/timing issue or cache thingy I'm messing up or don't understand?
 

Attachments

  • 8930_2013-04-23_00001.jpg
    8930_2013-04-23_00001.jpg
    160.8 KB · Views: 46
  • 8930_2013-04-23_00002.jpg
    8930_2013-04-23_00002.jpg
    145.1 KB · Views: 40
  • 8930_2013-04-23_00003.jpg
    8930_2013-04-23_00003.jpg
    104 KB · Views: 105
Stating the obvious here, but TechTree.lua is running in a different state than the rest of your mod, so it can't call functions directly or access your mod "globals" (though it does have the same access to GameInfo and ModMapData).
 
Okay, it's confirmed all three places definitely call the same code. There is some kind of sequence of events going on here I don't understand yet. The tech tree gets called and populated non-dynamically. The other two places dynamically. Though I am not 100% sure on that yet. I know the tech tree is built on game init before you even press the 'begin' button. But it never seems to get called again. Which makes some amount of sense, because they entire tree builds a bit slow and users would notice the delay.

The end result though is, I'm not sure I can hide wonders on the tech tree (just in the other two places and who cares for this mod), without introducing an unacceptable amount of overhead, or doing a ton of lua coding to re-write the entire dang thing.
 
You can call InitialSetup() in TechTree.lua during game. I do this with mine to toggle everything left right (after I moved the scrollbar to vertical), and it rebuilds everything fast enough to not be a problem for UI. Just remember to:
  1. ResetInstances() on g_PipeManager, g_EraManager and g_TechInstanceManager (else you will just accumulate new instances drawn on top of old ones)
  2. Empty out the three tables defined just before InitialSetup() (techButtons, etc.)
  3. (Not really necessary) Put all the Controls stuff (SetSize, CalculateInternalSize) behind an init check. Don't need to rerun this, though it won't hurt if you do.
  4. For reasons I don't understand, I needed to change extraYOffset from 32 to -330 after the pre-init call. Without this, everything got shifted way down. It may be a mod-specific value, but -330 got everything back to the proper vertical.
 
I took a different route, which seems to be working. There is a function on open that checks variables to see if it needs to refresh on open. I tweaked that function to always refresh on open. Upside: works like a charm. Downside: TechTree.lua has to be made part of my mod :( I wonder how many mods touch that, and if it's a big issue...
 
Downside: TechTree.lua has to be made part of my mod :( I wonder how many mods touch that, and if it's a big issue...

Only mods that alter the Tech Tree, and you'll probably already incompatible with those anyway.

My personal view is that Mod Component style mods should try to only touch existing files that affect one area, eg TechTree, Religions, etc, and avoid files that affect several areas, eg UnitPanel (promotions, builds, found city, display XP/HP, etc), ActionInfoPanel (next turn, turn blocking, notifications, choose great people, etc), InfoPanel (top-left) (unit list, tech tree view, great people, etc). A Tech Tree mod that's incompatible with another Tech Tree mod is understandable by even the newest of players, but a mod that adds a new unit action that also breaks a promotion selection mod is slightly harder to explain/understand (as most players don't read/understand a mod's description that says "changes core files xyz.lua", especially as not all mods carry that information in their description)
 
Back
Top Bottom