Static variables are only used for constant values; it would not be at all safe to use them to hold data that changes.
May I ask why? I have several times utilized changing Static values, as Static (should) only indicates that all instances of a class share the variable value. Are you referring to "Final", or am I missing something here?
Right, you're (naturally) correct about how static variables work. Where it gets really iffy is when you combine that with state transitions and/or loading a new game. Say you have a hullmod and a static variable, I don't know, holds a list of ships that are currently under the effect of that hullmod's... some kind of AoE field. And you're doing this as a way make sure that multiple AoEs don't affect the same ship.
So that's all well and good, but when you exit combat, that list is still around, unless you make sure to clean it up, and the elements in it may point to the combat engine /and/ to the campaign engine. So, that's one combat engine leak right there. Then you load a new game. That list is *still* around, and points to the old game engine, preventing it from being GC'ed. That's an even more severe leak of one campaign engine instance.
Less problematic issues are non-leaking bugs of the same variety, i.e. a counter or some such that doesn't get reset when another savegame is loaded, that sort of thing.
You certainly /can/ use changing static variables safely. It's just often a bit of a pain and it seems easier to use combat/campaign.getCustomData() which means you don't need to worry about these kinds of scoping issues.
Oh and sorry for double posting, but I had an unrelated question regarding fighters in the refit screen:
I'm trying to make a hullmod (on a fighter) which changes effect depending on the ship it is mounted on. Is there any way to, in the refit screen, get
A: The fighter's associated ship?
B: The fighter's associated wing?
C: The fighter's associated fleet?
ShipAPI.getWing returns null, which means that A and B seem impossible to me, but i have not found any function to get C working. Am i missing a function, or is there simply no way for a fighter to know which ship it is mounted on before entering combat? It should be noted that the opposite does not seem to work, either (ShipAPI.getAllWings returns an empty list, so the carrier seems unaware of the fighters it carries until it enters battle).
Hmm, I think you're out of luck on this one - the fighters, as far as I recall, don't exist in the refit screen. I couldn't tell you if their hullmods even get their apply() method called - if they do, it's more of a "side effect" than a feature you can rely on continuing to exist.