Make 2 version of same code

BlitzMax Forums/BlitzMax Beginners Area/Make 2 version of same code

MOBii(Posted 2014) [#1]
http://en.wikibooks.org/wiki/BlitzMax/Language/Conditional_Compiling

Example:
Global QVew:Int = True

?Not QVew
DebugLog "This is running Always: True/False"
?QVew
DebugLog "This is Never running: True/False"
?
DebugLog "OK Always Running"
Can I set what code that is going to compile?


Derron(Posted 2014) [#2]
The identifiers are fixed.

Custom identifiers:

global QVew:Int = true
if QVew
  debuglog "bla"
else
 debuglog "blubb"
endif


--> so the same procedure as usual.

bye
Ron


MOBii(Posted 2014) [#3]
Was wondering if I could exclude code to the compiler somehow:
Don't compile this code and this and this..

Build 1 is the code I have now
Build 2 exclude the graphical interface (that is like 50% of the code)
But I still need some of the graphical GUI

If I split the code then I have 2 code to update
I guess a normal If is my best option after all, Thanks Ron


Xerra(Posted 2014) [#4]
Could you not have the gui code in a separate source file and just include it into the main code?

That way you could compile it with the include line active and just comment that line out for the second version?


MOBii(Posted 2014) [#5]
I make another try to see why I could not reach: wxWidgets MyFrame from MyMOBii

This is my attempt

MyFrame.bmx:
Import "MyCode.bmx"
Global MFrame:MyFrame
Global MyMOBii:MOBii = New MOBii
Type MyFrame Extends wxFrame
...
End Type

MyCode.bmx:
Import "MyFrame.bmx"
Type MOBii Extends MyFrame
...
End Type
When testing I get this ERROR:
Compile Error: Duplicate identifier 'MyFrame'
Build Error: failed to compile C:/BlitzMax/MOBii/BLL/MyCode.bmx



It be fantastic if this would work, I say


MOBii(Posted 2014) [#6]
I erase all file in .bmx
I change MyFrame to MOBii in:
Type MyApp Extends wxApp
	MyMOBii = MOBii(New MOBii.Create(,,, 0, 0, 100, 100))
End Type


Then I get
Compile Error: Unable to open file '.bmx/MyCode.bmx.debug.win32.x86.i'

If I move/rem the: Import "MyCode.bmx"
MyFrame want: MyCode.bmx.debug.win32.x86.i
and MyCode.bmx want: MyFrame.bmx.debug.win32.x86.i

I am working to make: MyFrame.bmx independent
I am still little impressed I never come this far without try explain the problem
(Thinking out Loud)


Derron(Posted 2014) [#7]
You created a cyclic dependency:

"MyFrame" imports "MyCode" (which says: compile "MyCode" first, then "MyFrame")

"MyCode" imports "MyFrame" (which says: compile "MyFrame" first, then "MyCode").


Restructure your code to avoid this dependency.

bye
Ron


MOBii(Posted 2014) [#8]
I been sitting 7 hour now and try make MyFrame.bmx independent
I try move all MyFrame bla bla from other types to MyFrame
Then I get to my biggest type that have nestled code with MyFrame
So I made it:
Type BiggestType Extends wxFrame

Fixing my wrong make me realize I just move all the code to a new file but don't make the code splittable just make it independent.
(I had to plan this from the beginning)

these 7 hour make me understand the Power and the use of: Extends
and the importance to keep the function inside the Type
I think this is called learning the hard way ^^

I Reload my 7 Hour old backup and continue with My Life


Derron(Posted 2014) [#9]
Removing cyclic dependencies has multiple approaches:

The easiest one for you in BlitzMax is this

file "mytypebase.bmx"
Type MyTypeBase
  Method Move() abstract
End Type


file "mytype.bmx"
Type MyType extends MyTypeBase
  Method Move(); dosomething; End Method
End Type


file "mycode.bmx"
Import "mytypebase.bmx"

Type MyCode
  Field mytype:MyTypeBase
  Method Update()
    mytype.Move()
  End Method
End Type

file "main.bmx"
Import "mycode.bmx"
Import "mytype.bmx" 'the extended one !
global code:MyCode = new MyCode
code.mytype = new MyType

code.update() 'will run Move() of MyType while "MyCode" just knows about "MyTypeBase"


This is similar to "interfaces", but this is not existing in "vanilla blitzmax" (think Yasha posted something "interface"like some months ago).


bye
Ron


MOBii(Posted 2014) [#10]
I shall make time and do this example when my head is back to normal, so I can feel and play with the code!

For my splitting:
Import "mytypebase.bmx"

Type MyCode
  Field mytype:MyTypeBase
I think this is what I need todo to split my 2 Type that has nestled-ed code.
Thank thee I learn a lot today!

http://en.wikibooks.org/wiki/BlitzMax/Language/User_Defined_Types