?If Defined

BlitzMax Forums/BlitzMax Programming/?If Defined

H&K(Posted 2006) [#1]
Ive decided to put all my types into seperate files, which seemed a sencible thing to do when I started, and with the first few was realy simple.

Unfortunatly Ive got to the cyclic reference ones, and the duplicate dependancey ones, so Im starting to get Duplicated Definition errors. (I realise that when Ive actualy fininshed then it wont be a problem, but at the moment it is)

So, I remember from CS classes that VC had a IF not Defined thing were by you defined a system variable inside the if, then if it was defined the next time then it wouldnt include the file. So.
?If Not Defined MyTypeFlag
Include "MyType.Bmx"
?Endif
Then in "MyType.Bmx"
?Define MyTypeFlag = True
Can I do this in Bmax, if not what can I do to achieve the same effect

I realise That I could just do it and try, but then I would missout on all you advice ;)

Thanks


AlexO(Posted 2006) [#2]
I've always put my types in different files in blitzmax. It makes it much easier to work on a game when you might have more than 1 person working on something. What you seem to be alluding to is what the function of 'import' does. Including simply does a replace of that line with your actual code.

example:
- Files A,B,C,D all need MyType.
- MyType is in a different file called 'MyType.bmx'
- At the top of files A,B,C,D instead of 'include' I use import "MyType.bmx". It will compile MyType once and link that object file with each file that needs it.

For cyclic references I can't offer too much advice except trying to refactor to remove it (sometimes this is easier than trying to force it to work). Otherwise, if those two types are very tightly coupled, Then I would just put both in the same file and consider it a single 'module' that you have to import as a whole. I do this sometimes for large utility types that might use smaller helper-type classes to handle data.


Dreamora(Posted 2006) [#3]
No there is no "definition mechanism".
It wouldn't help anyway because Import means compile the other bmx and link to it. At that point the define does not work anymore.

The "most usefull" way is what I normally call "package" approach.

Do a main file (in Alex case I would use MyType as that) and include all cross - referenced class bmx into that MyType.bmx

Then after that you would just import mytype into your project and with quick compile it would only change if mytype or A,B,C or D changes ... so those 5 form an enclosed package