Conditional compiling lets one program build for several targets. Code inside an #If block is only compiled when its condition is true. When it's false, the code is left out completely, as if it wasn't there, so it can use commands, Imports and Includes the current target doesn't have.
#If DESKTOP
Print "desktop"
#ElseIf WEB
Print "web"
#Else
Print "something else"
#EndIf
#ElseIf and #Else are optional. #End If works as well as #EndIf. The # lines go at the start of a line (spaces in front are fine), and an #If has to end in the same file it starts in.
The target you build for sets these names:
| Name | Set when building for |
| DESKTOP_WIN | Desktop on Windows |
| DESKTOP_VK | Desktop (Vulkan) on Windows |
| DESKTOP_DEB | Desktop on Linux (Debian, Ubuntu, Mint) |
| DESKTOP_ARC | Desktop on Linux (Arch, CachyOS) |
| DESKTOP | Any of the four desktops |
| WEB_GPU | Web (WebGPU) |
| WEB_GL2 | Web (WebGL2) |
| WEB | Either web target |
| TARGET_PS1 | PlayStation |
| TARGET_USB | USB (ISO). It isn't one of the DESKTOP names |
A name that isn't set counts as false. Names aren't case sensitive.
A condition can use Not, And, Or and brackets, as well as True and False:
#If WEB And Not DEBUG_ON #If (DESKTOP Or TARGET_USB) And SOUND #If False
Names are only on or off: there are no values to compare.
#Define SHOW_DETAILS
#If SHOW_DETAILS
Print "score: " & ToString(score)
#EndIf
A #Define counts from its line onwards, including in the files included after it. Put your #Defines near the top of the main file, before its Includes. A #Define inside an #If block that's left out doesn't count. The target names can't be #Defined.
Each target has its own runtime to import, and #If lets one file pick the right one:
#If DESKTOP Or TARGET_USB Import "BBRuntimeLinux.decls" #ElseIf WEB_GPU Import "BBRuntimeWeb.decls" #ElseIf WEB_GL2 Import "BBRuntimeWebGL2.decls" #EndIf
#If False switches a block off without commenting out every line. The code in it is never read, so it doesn't even have to be finished:
#If False
OldDrawRoutine()
half-written idea, not BambooBasic yet
#EndIf
The # lines are shown in the keyword colour, and the code the selected target leaves out is greyed out. Change the Target menu and it updates. In a file that's included by another, the greying only knows about that file's own #Defines.
See the Conditional Compiling Example: one program that builds for every target.
BambooBasic © 2026 Michael Denathorn