Confirming that Something has been Validly Defined in xml

Lplate

Esus (Allegedly)
Joined
Feb 8, 2011
Messages
578
Location
Ireland
Hi,

Is there a way in python to check if something is validly defined information?

Generally, I work using the modular python in RifE. One of the python files that I'm considering editing has not been exposed to modular callback within RifE. The original python file would need to be replaced with mine by someone considering using my module.

However, I don't want someone to have the hassle of having to keep manually switching a python file whenever they enable/disable the module. What I'd like to include is a check to see if one of the module's xml defined features is defined. If it isn't, the module isn't installed and my addition in the python file should be ignored. If the modular xml is there to support it, then the added python should work fine.

Is there someway to check this?
 
That isn't that tricky.

GlobalDefinesAlt.xml
Code:
 <Define>
    <DefineName>FLAG_TO_TELL_MY_NEW_SETTING</DefineName>
    <iDefineIntVal>1</iDefineIntVal>
  </Define>

in python
Code:
if (gc.getDefineINT("FLAG_TO_TELL_MY_NEW_SETTING") == 1):
    call your python file
gc.getDefineINT() returns 0 unless specifically set to some other value in XML. At least that is how it works in the DLL and I assume it's the same code in python as well.

gc.getDefineINT() is kind of slow btw. You may consider caching the output if you make the check really often. On the other hand if you have performance issues in what you write, then you shouldn't write it in python.

Disclimer: I quickly wrote the code directly in the forum and it is totally untested. However the concept should work just fine.
 
Thanks for the suggestion. Your python code works fine if I edit the core GlobalDefinesAlt.xml as you suggest.

Unfortunately, I can't seem to get a modular GlobalDefinesAlt.xml recognised. If I need to change the core GlobalDefinesAlt.xml, then I'm essentially back to square one.

The position of the core GlobalDefinesAlt.xml file is in the Assets/xml folder and so I've tried placing my modular version directly in the module folder (i.e. Not in a sub-folder). I've used both GlobalDefinesAlt.xml and ModuleName_GlobalDefinesAlt.xml as names for the modular global defines but it is not being recognised. Any suggestions?
 
The only thing I can think of is adding some XML to your module and then use getDefineINT() to check that. Say you add two new units, then get the defined int for the last one. If it is different from 0, then your mod is loaded. Other XML should be possible too. A fallback is to make two bogus units, which are graphical only and not used in the game. The bad thing about using units is if some other module uses the very same unit name, then your mod is loaded. Make sure the <Type> is set to something, which is really unlikely to be used by any other mod.

Another solution would be to get the DLL to check if your file is present. However as I read what you are trying to do, replacing the DLL is somewhat out of the scope. Maybe python could be used to tell if a file is present or not, but I have no idea how that would work.
 
GetInfoTypeForString will return -1 if an item is not defined so you can use that. Just define a help item for the civpedia in your module and check that one.
Code:
		<ConceptInfo>
			<Type>CONCEPT_CRIME_RATE</Type>
			<Description>TXT_KEY_CONCEPT_CRIME_RATE</Description>
			<Civilopedia>TXT_KEY_CONCEPT_CRIME_RATE_PEDIA</Civilopedia>
		</ConceptInfo>

if gc.getInfoTypeForString('CONCEPT_CRIME_RATE') != -1:
 
GetInfoTypeForString will return -1 if an item is not defined so you can use that. Just define a help item for the civpedia in your module and check that one.
Code:
		<ConceptInfo>
			<Type>CONCEPT_CRIME_RATE</Type>
			<Description>TXT_KEY_CONCEPT_CRIME_RATE</Description>
			<Civilopedia>TXT_KEY_CONCEPT_CRIME_RATE_PEDIA</Civilopedia>
		</ConceptInfo>

if gc.getInfoTypeForString('CONCEPT_CRIME_RATE') != -1:

That works. Thanks.
 
Back
Top Bottom