Is there any reason not to massively use Global Defines in the SDK?

Maniac

Apolyton Sage
Joined
Nov 27, 2004
Messages
5,588
Location
Gent, Belgium
For instance saying directly:

Code:
if (getNumRealBuilding((BuildingTypes)GC.getInfoTypeForString(GC.getDefineSTRING("BUILDING_INFESTATION"))) > 0)
{
blah blah...

instead of adding the required XML tags and support code in the Infos file etc. If you're not concerned about making your code easily moddable for not-SDK modders that is. Does using GlobalDefines slow down the game in any way?

Just wondering, 'cause often not having to write all that SDK support code could save a lot of time.
 
I always thought it was bad form to hardcode XML related things into the SDK, but maybe that's just me.
 
I always thought it was bad form to hardcode XML related things into the SDK, but maybe that's just me.
Nah, that's what my lecturer told me as well - hard coding stuff is bad programming practice for several reasons:
1) Lack of flexibility with the code (like when you want to add the function to something else or so)
2) Makes it harder to understand/fiddle/tweak for other people
3) Makes it harder for you to understand, because now you need to keep track of your data/parameters in your code as well, instead of just the way it works
4) You get used to that and keep doing that over and over again and at some point, you have a mess that's too entwined with everything else to debug it easily.

But then, I only program for data acquisition and analysis stuff for my study, where you do want to fiddle with the parameters a lot and keeping it in an extra file is neater and worth the extra coding. For a mod and if you don't program for anything else (so bad habits aren't really relevant)...

Cheers, LT.
 
Typically, taking the time to code the new XML field saves you a LOT of time later on, as long as you generalize it enough that you wind up using it again later. If what you are looking to do is REALLY specific and there is NO way you EVER apply it to anything else, then try to do it with python instead of the DLL. If the area you need to modify isn't able to be interacting with python, introduce the ability to interact, THAT might be useful later. If the overhead cost of adding a python call there is too much (function is called very often), then you still SHOULD write up an XML field ideally, but slipping in a Global Define is fine. Just make sure that if the global define isn't set, or is invalid, the code doesn't break, but rather skips over the "Special treatment" section.


To directly answer though: No, it won't make things slower as far as how the code runs. Might even make it faster. It just complicates your own life in the future when re-coding things.
 
Top Bottom