Exclude data when compiling?

BlitzMax Forums/BlitzMax Beginners Area/Exclude data when compiling?

Lillpeter(Posted 2005) [#1]
Iīm currently creating timers and stuff to debug my game with, and i wonder if there is a way of exclude that debug code (if i choose to) when compiling. Can i flag certain peices of code to be excluded ( if debug_exclude = false ) or something, A friend of mine explained how you can flag stuff in C++ to be excluded when compiling but i dont know if i can do that in Bmax.


tonyg(Posted 2005) [#2]
?debug
?debug
  Print "Hello"
?
Print "World"

Run in debug and non-debug mode to see the difference.


klepto2(Posted 2005) [#3]
You can use Compiler Directives in Bmax.

For Example:


?debug
Print "I'm only visible in DebugMode"
?
Print "I'm visible everytime"



Who was John Galt?(Posted 2005) [#4]
Ahh good. How about the other way round - if I want stuff excluded in the debug build?


Hotcakes(Posted 2005) [#5]
You're screwed. Use temp variables =]


tonyg(Posted 2005) [#6]
You'd have to use...
Const DEBUG = 1

If DEBUG Then
  Print "hello world"
End If 

and change the const to 0 for not including in debug mode. Doesn't match the compile option but would have the same result.


Lillpeter(Posted 2005) [#7]
Where can i find information about the debug mode and all thatīs related to that, or could anyone explain it to me, i donīt know anything about it and i canīt find any info in the help file, iīm new to this, and debugging in general too.


Who was John Galt?(Posted 2005) [#8]
Thanks tony.


Perturbatio(Posted 2005) [#9]
You could do:
Global DEBUG:Int = False
?debug
	DEBUG = True
?

If Not DEBUG Then
	Print "in release mode"
Else
	Print "in debug mode"
EndIf


so that you don't have to change the debug const each time


JazzieB(Posted 2005) [#10]
The only problem with that is that the code would get compiled for both debug and non-debug modes regardless of whether you're in debug mode or not. This is because you've used a global for your debug flag and the compiler doesn't know that you will never change the value of that flag during the execution of your program.

If you want different sections of code to be executed/compiled depending on whether you're in debug mode use a constant instead. Since constants don't change the compiler won't compile anything that will never get executed that is based solely on the value of a constant. At least this was the case with B3D, so I'm assuming this is the case with BlitzMax also. Someone correct me if I'm wrong.

However, why would you want a *different* section of code to be executed during debug mode that would not be executed in the full release? The debug directives are there for *additional* code that is there to simply report back on the status of the program for testing purposes.

Hope that last paragraph made sense, but as an extreme example it would be like having two completely different game rendering functions where one is used in debug mode and one is used in release mode - why would you want to do this? I'm guessing not.


Who was John Galt?(Posted 2005) [#11]
While I'm testing (in debug mode) I don't need stuff like start screens and the like displayed - as all the incbins and loading slows the process down.


JazzieB(Posted 2005) [#12]
A valid point, I didn't think of that. However, I usually leave stuff like that until the end. When I do finally include it, I have some way of skipping it.


Ferminho(Posted 2005) [#13]
I use a global variable that keeps track of the current state of the game (intro, menu, startgame menu, playing, paused...). I do something like that

Status = SINTRO
?Debug
Status = SPLAYING
?

(more or less) So then the game will skip to playing directly.