#constant MYVALUE 5
Anytime you put MYVALUE into your code it is replaced with whatever you have written after MYVALUE, in this case 5, by the pre-processor. This can be used to replace values that don't change during runtime, but that you might want to change later without having to change the value every place you have it in the code.
Basically it's not set up as a variable in the final program it's just a label for "5". (not including the "s)
You can also make macro's like this:
#constant MYMACRO print "HELLO " + str$(5) + " GOODBYE"
MYMACRO
MYMACRO
MYMACRO
end
This would print 3 lines like this: HELLO 5 GOODBYE
In other languages like C++ you can string multiple commands together in one macro, but DBP seems to limit this to only 1 command.
Here's a more interesting example:
#constant GOLEFT dec x, 1
#constant GORIGHT inc x, 1
#constant SHOWX print "X = " + str$(x)
x = 10000
repeat
cls 0
SHOWX
if leftkey() then GOLEFT
if rightkey() then GORIGHT
until returnkey()
end
This will print the value of X every loop, and you can dec/inc it with the left/right arrowkeys.
Notice that the variable X doesn't need to be setup before defining the macros, as they are just a string that will replace the macro name when the pre-processor sees it. X could be replaced by Player.X and it would still be fine, as long as Player.x is defined before the MACRO is used.