top of page

LANGUAGE STRUCTURE

 

Everything that is valid and can be written in 3D Basic belongs to one of the following six main groups:

 

  1. Objects

  2. Attributes

  3. Instructions

  4. Mathematical expressions

  5. Prefix group

  6. Literal / Value

-------------------------------------------------------------------------------------------

1. What is an object in 3D Basic?

 

The easiest way to recognize an object is that it always has a name, and it usually appears first on a line—unless the line begins with an instruction.

 

Objects can be seen as the nouns of the language: a box, a cylinder, a sound, a camera, and so on. An object is automatically created the first time you write its name.

 

Example:

10 box1.size = (2, 3, 1)

Here, box1 is the object, and size is an attribute that defines the object's dimensions.

 

Syntax:

objektNamn.attribut = värde

-------------------------------------------------------------------------------------------

2. What is an attribute in 3D Basic?

 

An attribute describes the properties of an object.
Attributes can be compared to adjectives—they describe how something is: color, size, position, material, rotation, etc.

 

An object can have many attributes. Not all objects share the same attributes; each object type has its own set of available properties.

 

Example:

10 box1.size=(2,2,2)

20 box1.move=(0,1,0)

30 box1.color=red

40 box1.draw

-------------------------------------------------------------------------------------------

3. What are instructions?

 

Instructions are commands that control the flow of the program or perform a direct action.

 

Unlike objects and attributes—which describe what something is and how it looks—instructions describe what should happen.

 

They can be compared to verbs: they do something—start, draw, play, change view, or exit.

 

Example:

if varX = 1 then call sublandscape

 

Here, three instructions are used: if, then, and call.
Together, they control the program flow and determine when and what should be executed.

 

The most common instruction in 3D Basic is probably draw.
Even though it looks like an attribute (because of dot notation), it functions as an instruction since it performs an action—it renders the object on screen.

 

Example:

box1.size = (2, 2, 2)

box1.draw

 

Other instruction examples, similar to classic BASIC:

for, next, sleep, goto, else, exit

Instructions are the active parts of the language—they make the code come alive and move forward. -------------------------------------------------------------------------------------------

4. What are mathematical expressions?

 

Mathematical calculations are often used in 3D Basic to compute positions, distances, rotations, random values, and much more.

 

Using the calc group

All mathematical expressions in 3D Basic are handled through the calc group.
It is used for various types of calculations—from distance and randomness to interpolation and trigonometric functions.

 

Syntax:

calc.uttryck(värden) = variabel

 

Example: calculating the distance between two points in 3D space:

calc.distance(x1, y1, z1) to (x2, y2, z2) = varLength

 

For simplicity, some common functions also have shorter aliases:

RND = calc.dice

LERP = calc.findBetween

COS = calc.curve

DIST = calc.distance

 

Date and time

Date and time can also be calculated via the calc group.

A complete list of all available calc expressions, their usage, and syntax can be found in the mathematics section of the manual.

-------------------------------------------------------------------------------------------

5. What belongs to the prefix group?

 

The prefix group consists of words and symbols placed before objects, attributes, or values to affect their meaning or usage.

 

They function like helper words in a language—they modify interpretation without being objects or instructions themselves.

 

Prefixes are used in many contexts in 3D Basic, for example to indicate data types or structural roles.

-------------------------------------------------------------------------------------------

Common prefixes

var prefix

used to create and name variables.

All variables that store values should begin with var for clarity.

Example:

varStart = 1

varSpeed = 5

-------------------------------------------------------------------------------------------

sub-prefix
Used to define and call subroutines.
Subroutines are independent code blocks that can be called from different parts of the program.

 

Example:

call subLandscape

-------------------------------------------------------------------------------------------

label prefix
Used to mark specific positions in the program, often as a complement to line numbers.
A label acts as a named point you can jump to using, for example, goto, or as a visual marker.

 

Example:

90 labelEND

100 exit

-------------------------------------------------------------------------------------------

Prefixes in 3D objects

All 3D objects in 3D Basic have their own internal prefixes for surfaces or parts.

 

For example, a box has six sides labeled b1 to b6.
Each side can have its own properties.

 

Example:

box1.b1.color = red ' Side b1 of the box becomes red

 

This makes it possible to control detailed properties of individual parts of the same object.

-------------------------------------------------------------------------------------------

Other prefixes

In some parts of 3D Basic—such as the avatar system in game development—special predefined prefixes are used to identify and manage different types of characters, objects, and states.

 

These are covered in more detail in the game development section of the manual.

 

The prefix group is therefore an important part of the language, contributing to clarity, structure, and specialized functionality.

-------------------------------------------------------------------------------------------

6. What are literals and values?

After the equals sign (=), only two types of values are allowed:

 

1. Value

A numeric value (integer or decimal).

 

Examples:

objectName.size = value ' t.ex. ( 5, 10, 3.5)

objectName.move = value ' t.ex. ( -2, 0, 7.8)

 

2. Literal

A literal value such as a word, a boolean (true/false), or another non-numeric value.

Examples:

 

particleName.fireworks.type = literal ' e.g. flower, comet, palm
window1.caption = literal ' e.g. "Hello World"
objectName.visible = literal ' true or false
objectName.color = literal ' e.g. red, blue, green
objectName.linear = literal ' e.g. red to blue
objectName.image = literal ' e.g. "image1.jpg"

 

 

Note – Language rule:
Nothing other than a value or a literal is allowed after =.

bottom of page