OpenDBC
Menu

Basic commands

Control-flow statements (IF, THEN, FOR, WHILE…), declarations, operators and directives.

75 entries (statements, directives, operators).

Type and status legend

Statements

AS dbproStatement

Compatibility: dbpro

DBPro only: gives the type of a variable, a TYPE field or a function parameter.

Implemented in OpenDBC

Syntax

Variable AS Datatype

Example

counter as integer
name$ as string
counter = 42
print counter
wait key

BOOLEAN dbproStatement

Compatibility: dbpro

DBPro only: boolean type used with AS.

Implemented in OpenDBC

Syntax

Variable AS BOOLEAN

Example

active as boolean
active = 1

BYTE dbproStatement

Compatibility: dbpro

DBPro only: unsigned 8-bit integer used with AS.

Implemented in OpenDBC

Syntax

Variable AS BYTE

Example

b as byte
b = 255

CASE dbcdbproStatement

Compatibility: dbc and dbpro

Branch of a SELECT: the block runs when the SELECT variable equals the given value.

Implemented in OpenDBC

Syntax

CASE Value
   Actions
ENDCASE

Example

weapon = 1
select weapon
   case 1 : print "Sword" : endcase
   case 2 : print "Bow" : endcase
endselect
wait key

CASE DEFAULT dbcdbproStatement

Compatibility: dbc and dbpro

Default branch of a SELECT, executed when no CASE matches.

Implemented in OpenDBC

Syntax

CASE DEFAULT
   Actions
ENDCASE

Example

n = 99
select n
   case 1 : print "one" : endcase
   case default : print "something else" : endcase
endselect
wait key

DATA dbcdbproStatement

Compatibility: dbc and dbpro

Declares constant values read sequentially with READ; RESTORE repositions the read cursor.

Implemented in OpenDBC

Syntax

DATA Value [, Value…]

Example

data 10, 20, 30
for i = 1 to 3
   read v
   print v
next i
wait key

DEC dbcdbproStatement

Compatibility: dbc and dbpro

Decrements a variable by 1 or by the given amount.

Implemented in OpenDBC

Syntax

DEC Variable [, Amount]

Example

lives = 3
dec lives
print lives
wait key

DIM dbcdbproStatement

Compatibility: dbc and dbpro

Declares an array (up to 5 dimensions in DBC). Arrays keep their historical shared namespace, including inside functions.

Implemented in OpenDBC

Syntax

DIM Array Name(Size [, Size…])

Example

dim scores(9)
for i = 0 to 9
   scores(i) = rnd(100)
next i
print scores(0)
wait key

DO dbcdbproStatement

Compatibility: dbc and dbpro

Opens an infinite DO/LOOP loop, the classic main loop of a game. Leave it with EXIT, GOTO or END.

Implemented in OpenDBC

Syntax

DO
   Actions
LOOP

Example

sync on
do
   text 10, 10, "main loop"
   sync
loop

DOUBLE FLOAT dbproStatement

Compatibility: dbpro

DBPro only: 64-bit real used with AS.

Implemented in OpenDBC

Syntax

Variable AS DOUBLE FLOAT

Example

precise as double float
precise = 3.14159265358979

DOUBLE INTEGER dbproStatement

Compatibility: dbpro

DBPro only: signed 64-bit integer used with AS.

Implemented in OpenDBC

Syntax

Variable AS DOUBLE INTEGER

Example

big as double integer
big = 4000000000

DWORD dbproStatement

Compatibility: dbpro

DBPro only: unsigned 32-bit integer used with AS (colors, handles…).

Implemented in OpenDBC

Syntax

Variable AS DWORD

Example

color as dword
color = rgb(255, 128, 0)

ELSE dbcdbproStatement

Compatibility: dbc and dbpro

Alternative branch of an IF block, executed when the condition is false.

Implemented in OpenDBC

Syntax

IF Condition
   Actions
ELSE
   Other actions
ENDIF

Example

age = 15
if age >= 18
   print "Adult"
else
   print "Minor"
endif
wait key

ELSEIF dbproStatement

Compatibility: dbpro

DBPro only: chains another condition inside an IF block without nesting a new block.

Implemented in OpenDBC

Syntax

IF Condition1
   …
ELSEIF Condition2
   …
ELSE
   …
ENDIF

Example

grade = 14
if grade >= 16
   print "Very good"
elseif grade >= 10
   print "Pass"
else
   print "Fail"
endif
wait key

END dbcdbproStatement

Compatibility: dbc and dbpro

Ends the program immediately.

Implemented in OpenDBC

Syntax

END

Example

print "done"
wait key
end

ENDCASE dbcdbproStatement

Compatibility: dbc and dbpro

Ends the block of a CASE or CASE DEFAULT.

Implemented in OpenDBC

Syntax

CASE Value
   Actions
ENDCASE

Example

select 1
   case 1 : print "ok" : endcase
endselect
wait key

ENDFUNCTION dbcdbproStatement

Compatibility: dbc and dbpro

Ends a function; the expression that follows it becomes the return value.

Implemented in OpenDBC

Syntax

ENDFUNCTION [Return Value]

Example

print double(21)
wait key
end
function double(n)
endfunction n * 2

ENDIF dbcdbproStatement

Compatibility: dbc and dbpro

Ends a multi-line IF block.

Implemented in OpenDBC

Syntax

IF Condition
   Actions
ENDIF

Example

if mouseclick() = 1
   print "Left click"
endif

ENDSELECT dbcdbproStatement

Compatibility: dbc and dbpro

Ends a SELECT branch.

Implemented in OpenDBC

Syntax

SELECT Variable
   …
ENDSELECT

Example

select 0
   case default : print "default" : endcase
endselect
wait key

ENDTYPE dbproStatement

Compatibility: dbpro

DBPro only: ends a user-defined type declaration.

Implemented in OpenDBC

Syntax

TYPE Name … ENDTYPE

Example

type point
   x as integer
   y as integer
endtype

ENDWHILE dbcdbproStatement

Compatibility: dbc and dbpro

Ends a WHILE block and jumps back to the condition test.

Implemented in OpenDBC

Syntax

WHILE Condition
   Actions
ENDWHILE

Example

while escapekey() = 0
   text 10, 10, "ESC to quit"
   sync
endwhile

EXIT dbcdbproStatement

Compatibility: dbc and dbpro

Immediately leaves the current loop (DO, FOR, WHILE, REPEAT).

Implemented in OpenDBC

Syntax

EXIT

Example

do
   if spacekey() = 1 then exit
loop
print "Out of the loop!"
wait key

EXITFUNCTION dbcdbproStatement

Compatibility: dbc and dbpro

Leaves a function early, with an optional return value.

Implemented in OpenDBC

Syntax

EXITFUNCTION [Return Value]

Example

print first_even(7, 10)
wait key
end
function first_even(a, b)
   if a mod 2 = 0 then exitfunction a
endfunction b

FLOAT dbproStatement

Compatibility: dbpro

DBPro only: 32-bit real used with AS (equivalent to the # suffix).

Implemented in OpenDBC

Syntax

Variable AS FLOAT

Example

ratio as float
ratio = 1.618
print ratio
wait key

FOR dbcdbproStatement

Compatibility: dbc and dbpro

Counted loop: repeats the block between FOR and NEXT while stepping the variable from the start value to the end value.

Implemented in OpenDBC

Syntax

FOR Variable = Start TO End [STEP Increment]
   Actions
NEXT Variable

Example

for i = 1 to 5
   print "lap ", i
next i
wait key

FUNCTION dbcdbproStatement

Compatibility: dbc and dbpro

Declares a user function. Scalar variables inside it are local; the return value is supplied by ENDFUNCTION or EXITFUNCTION.

Implemented in OpenDBC

Syntax

FUNCTION Name(Parameter List)
   Actions
ENDFUNCTION [Return Value]

Example

print area(3.0, 4.0)
wait key
end

function area(w#, h#)
   result# = w# * h#
endfunction result#

GLOBAL dbproStatement

Compatibility: dbpro

DBPro only: makes a variable visible in the whole program, including inside functions.

Implemented in OpenDBC

Syntax

GLOBAL Variable [AS Datatype]

Example

global score as integer
score = 0
gosub add_points
print score
wait key
end
add_points:
   inc score, 10
return

GOSUB dbcdbproStatement

Compatibility: dbc and dbpro

Calls a subroutine identified by a label; RETURN resumes execution after the GOSUB.

Implemented in OpenDBC

Syntax

GOSUB Label
…
Label:
   Actions
RETURN

Example

gosub show_title
print "rest of the program"
wait key
end

show_title:
   print "=== MY GAME ==="
return

GOTO dbcdbproStatement

Compatibility: dbc and dbpro

Unconditionally jumps to a label. Keep it for simple cases; prefer loops and functions.

Implemented in OpenDBC

Syntax

GOTO Label

Example

start:
print "again"
wait 500
goto start

IF dbcdbproStatement

Compatibility: dbc and dbpro

Runs code when a condition is true. Two forms: single-line IF … THEN action, or a multi-line IF / ENDIF block.

Implemented in OpenDBC

Syntax

IF Condition THEN Action
IF Condition
   Actions
ENDIF

Example

lives = 3
if lives = 0 then print "Game over"
if lives > 0
   print lives; " lives left"
endif
wait key

INC dbcdbproStatement

Compatibility: dbc and dbpro

Increments a variable by 1 or by the given amount.

Implemented in OpenDBC

Syntax

INC Variable [, Amount]

Example

n = 5
inc n
inc n, 10
print n
wait key

INTEGER dbproStatement

Compatibility: dbpro

DBPro only: signed 32-bit integer, the default numeric type, used with AS.

Implemented in OpenDBC

Syntax

Variable AS INTEGER

Example

n as integer
n = -42
print n
wait key

LOCAL dbproStatement

Compatibility: dbpro

DBPro only: explicitly declares a variable local to the current function.

Implemented in OpenDBC

Syntax

LOCAL Variable [AS Datatype]

Example

function compute()
   local temp as float
   temp = 1.5
endfunction temp

LOOP dbcdbproStatement

Compatibility: dbc and dbpro

Closes a DO loop and jumps back to the top of the block.

Implemented in OpenDBC

Syntax

DO
   Actions
LOOP

Example

do
   if escapekey() = 1 then end
loop

NEXT dbcdbproStatement

Compatibility: dbc and dbpro

Closes a FOR loop and moves to the next iteration.

Implemented in OpenDBC

Syntax

FOR Variable = Start TO End
   Actions
NEXT Variable

Example

for i = 10 to 1 step -1
   print i
next i
wait key

READ dbcdbproStatement

Compatibility: dbc and dbpro

Reads the next value declared with DATA into a variable.

Implemented in OpenDBC

Syntax

READ Variable

Example

data "sword", "bow", "shield"
read item$
print item$
wait key

REM dbcdbproStatement

Compatibility: dbc and dbpro

Single-line comment; the rest of the line is ignored. The backtick ` and // (DBPro) are shortcuts.

Implemented in OpenDBC

Syntax

REM Comment

Example

rem This is a comment
print "executed code"
wait key

REMEND dbcdbproStatement

Compatibility: dbc and dbpro

Closes a comment block opened by REMSTART.

Implemented in OpenDBC

Syntax

REMSTART … REMEND

Example

remstart
comments
remend

REMSTART dbcdbproStatement

Compatibility: dbc and dbpro

Opens a multi-line comment block closed by REMEND.

Implemented in OpenDBC

Syntax

REMSTART
   Comments
REMEND

Example

remstart
   This whole block is ignored.
remend
print "ok"
wait key

REPEAT dbcdbproStatement

Compatibility: dbc and dbpro

Conditional loop: repeats the block until the UNTIL condition becomes true; the block runs at least once.

Implemented in OpenDBC

Syntax

REPEAT
   Actions
UNTIL Condition

Example

repeat
   print "Press SPACE"
   wait 200
until spacekey() = 1

RESTORE dbcdbproStatement

Compatibility: dbc and dbpro

Repositions the DATA read cursor to the beginning or to a given label.

Implemented in OpenDBC

Syntax

RESTORE [Label]

Example

data 1, 2, 3
read a : read b
restore
read c
print c
wait key

RETURN dbcdbproStatement

Compatibility: dbc and dbpro

Ends a subroutine called with GOSUB and resumes after the call.

Implemented in OpenDBC

Syntax

RETURN

Example

gosub init
print "initialized"
wait key
end
init:
   randomize timer()
return

SELECT dbcdbproStatement

Compatibility: dbc and dbpro

Opens a multi-way branch on the value of a variable (integer, real or string), used with CASE, CASE DEFAULT, ENDCASE and ENDSELECT.

Implemented in OpenDBC

Syntax

SELECT Variable
   CASE Value : Actions : ENDCASE
   CASE DEFAULT : Actions : ENDCASE
ENDSELECT

Example

choice = 2
select choice
   case 1 : print "Play" : endcase
   case 2 : print "Options" : endcase
   case default : print "Quit" : endcase
endselect
wait key

STEP dbcdbproStatement

Compatibility: dbc and dbpro

Sets the (possibly negative) increment of a FOR loop.

Implemented in OpenDBC

Syntax

FOR Variable = Start TO End STEP Increment

Example

for i = 0 to 100 step 20
   print i
next i
wait key

STRING dbproStatement

Compatibility: dbpro

DBPro only: character string used with AS (equivalent to the $ suffix).

Implemented in OpenDBC

Syntax

Variable AS STRING

Example

name as string
name = "OpenDBC"
print name
wait key

THEN dbcdbproStatement

Compatibility: dbc and dbpro

Introduces the action of a single-line IF. Required in the single-line form, absent from the IF/ENDIF block form.

Implemented in OpenDBC

Syntax

IF Condition THEN Action

Example

score = 120
if score > 100 then print "Well done!"
wait key

TYPE dbproStatement

Compatibility: dbpro

DBPro only: declares a user-defined type (structure) whose fields are accessed with the dot operator.

Implemented in OpenDBC

Syntax

TYPE Name
   Field AS Datatype
   …
ENDTYPE

Example

type vec
   x as float
   y as float
endtype
pos as vec
pos.x = 3.5
print pos.x
wait key

UNDIM dbcdbproStatement

Compatibility: dbc and dbpro

Deletes an array declared with DIM and frees its memory.

Implemented in OpenDBC

Syntax

UNDIM Array Name(…)

Example

dim temp(100)
undim temp(100)

UNTIL dbcdbproStatement

Compatibility: dbc and dbpro

Closes a REPEAT loop; the loop stops when the condition becomes true.

Implemented in OpenDBC

Syntax

REPEAT
   Actions
UNTIL Condition

Example

counter = 0
repeat
   inc counter
until counter >= 10
print counter
wait key

WHILE dbcdbproStatement

Compatibility: dbc and dbpro

Conditional loop: repeats the block while the condition is true; the condition is tested before each iteration.

Implemented in OpenDBC

Syntax

WHILE Condition
   Actions
ENDWHILE

Example

n = 0
while n < 5
   print n
   inc n
endwhile
wait key

WORD dbproStatement

Compatibility: dbpro

DBPro only: unsigned 16-bit integer used with AS.

Implemented in OpenDBC

Syntax

Variable AS WORD

Example

w as word
w = 65535

Directives

#CONSTANT dbproDirective

Compatibility: dbpro

DBPro-only directive: declares a compile-time constant substituted textually before parsing.

Implemented in OpenDBC

Syntax

#CONSTANT Name Value

Example

#constant MAX_SPEED 8
print MAX_SPEED
wait key

#INCLUDE dbcdbproDirective

Compatibility: dbc and dbpro

Inserts another .dba source file into the project. The included file inherits the project profile (DBC or DBPro).

Implemented in OpenDBC

Syntax

#INCLUDE "Filename.dba"

Example

#include "tools.dba"
rem functions from tools.dba are available here

Operators

&& dbproOperator

Compatibility: dbpro

DBPro only: bitwise AND.

Implemented in OpenDBC

Syntax

a && b

Example

print 12 && 10
wait key

* dbcdbproOperator

Compatibility: dbc and dbpro

Multiplication.

Implemented in OpenDBC

Syntax

a * b

Example

print 6 * 7
wait key

+ dbcdbproOperator

Compatibility: dbc and dbpro

Numeric addition; also concatenates two strings.

Implemented in OpenDBC

Syntax

a + b

Example

print 2 + 3
print "Dark" + "BASIC"
wait key

- dbcdbproOperator

Compatibility: dbc and dbpro

Subtraction, or unary negation.

Implemented in OpenDBC

Syntax

a - b

Example

print 10 - 4
wait key

. dbproOperator

Compatibility: dbpro

DBPro only: access to a field of a user-defined type (TYPE).

Implemented in OpenDBC

Syntax

Variable.Field

Example

type player
   name as string
endtype
p as player
p.name = "Alex"
print p.name
wait key

/ dbcdbproOperator

Compatibility: dbc and dbpro

Division; between integers the result is truncated.

Implemented in OpenDBC

Syntax

a / b

Example

print 10 / 4
print 10.0 / 4.0
wait key

< dbcdbproOperator

Compatibility: dbc and dbpro

Strictly-less-than test.

Implemented in OpenDBC

Syntax

a < b

Example

if 3 < 5 then print "3 < 5"
wait key

<< dbproOperator

Compatibility: dbpro

DBPro only: bitwise left shift.

Implemented in OpenDBC

Syntax

a << n

Example

print 1 << 4
wait key

<= dbcdbproOperator

Compatibility: dbc and dbpro

Less-than-or-equal test.

Implemented in OpenDBC

Syntax

a <= b

Example

if 5 <= 5 then print "ok"
wait key

<> dbcdbproOperator

Compatibility: dbc and dbpro

Inequality test.

Implemented in OpenDBC

Syntax

a <> b

Example

if 1 <> 2 then print "different"
wait key

= dbcdbproOperator

Compatibility: dbc and dbpro

Variable assignment, and equality test inside a condition.

Implemented in OpenDBC

Syntax

Variable = Value   /   IF a = b

Example

n = 5
if n = 5 then print "equal"
wait key

> dbcdbproOperator

Compatibility: dbc and dbpro

Strictly-greater-than test.

Implemented in OpenDBC

Syntax

a > b

Example

if 5 > 3 then print "5 > 3"
wait key

>= dbcdbproOperator

Compatibility: dbc and dbpro

Greater-than-or-equal test.

Implemented in OpenDBC

Syntax

a >= b

Example

if 6 >= 5 then print "ok"
wait key

>> dbproOperator

Compatibility: dbpro

DBPro only: bitwise right shift.

Implemented in OpenDBC

Syntax

a >> n

Example

print 256 >> 4
wait key

AND dbcdbproOperator

Compatibility: dbc and dbpro

Logical AND between two conditions.

Implemented in OpenDBC

Syntax

Condition1 AND Condition2

Example

a = 3 : b = 7
if a > 0 and b > 0 then print "both positive"
wait key

MOD dbcdbproOperator

Compatibility: dbc and dbpro

Remainder of the integer division.

Implemented in OpenDBC

Syntax

a MOD b

Example

print 17 mod 5
wait key

NOT dbcdbproOperator

Compatibility: dbc and dbpro

Logical negation of a condition.

Implemented in OpenDBC

Syntax

NOT Condition

Example

if not (1 = 2) then print "1 is not 2"
wait key

OR dbcdbproOperator

Compatibility: dbc and dbpro

Logical OR between two conditions.

Implemented in OpenDBC

Syntax

Condition1 OR Condition2

Example

if spacekey() = 1 or returnkey() = 1 then print "confirmed"

XOR dbproOperator

Compatibility: dbpro

DBPro only: logical exclusive OR.

Implemented in OpenDBC

Syntax

a XOR b

Example

print 1 xor 0
wait key

^ dbcdbproOperator

Compatibility: dbc and dbpro

Exponentiation.

Implemented in OpenDBC

Syntax

a ^ b

Example

print 2 ^ 10
wait key

|| dbproOperator

Compatibility: dbpro

DBPro only: bitwise OR.

Implemented in OpenDBC

Syntax

a || b

Example

print 12 || 10
wait key

~~ dbproOperator

Compatibility: dbpro

DBPro only: bitwise exclusive OR.

Implemented in OpenDBC

Syntax

a ~~ b

Example

print 12 ~~ 10
wait key