Blitz3D+ Language Reference

Variables

Variables may be of any basic data type or a custom Type. A variable's type is determined by a special character that follows its identifier.

Variable Types

Extended mode adds :Long and :Double named annotations. See Long and Double for their declarations, literals, storage, and conversion rules.

These special characters are called type tags:

Type tag Variable type
% Integer
# Floating point
$ String
.TypeName Custom Type
:TypeName Custom Type with Dialect "modern"

Here are some examples of valid variables:

Score%
Lives%
x_speed#
y_speed#
name$
title$
ali.Alien
player.Player

The type tag only needs to be added the first time you use a variable. After that, you can leave the type tag off if you wish.

If you do not supply a type tag the first time a variable is used, the variable defaults to an Integer.

It is illegal to use the same variable name with a different type. For example, if you already have an Integer variable called name%, it is illegal to also have a String variable called name$.

Dialect "modern" uses player:Player. The historical player.Player form remains valid. See Modern dialect syntax.

Setting Variables

The = operator is used to assign a value to a variable. For example:

score% = 0

This assigns the value 0 to the Integer variable score.

Variable Scope

Variables may be either global or local. This determines where in a program the variable may be used.

Global variables can be used from anywhere in the program.

Local variables can only be used within the Function in which they are created.

The Global keyword is used to define one or more global variables. For example:

Global Score = 0, Lives = 3, Player_up = 1

This defines three global variables.

Similarly, Local is used to define local variables:

Local temp_x = x, temp_y = y

If you use a variable without defining it as either local or global, it defaults to being local.