Div Games Online
logo Div Games Online

Documentation: User Guide (Manual of Div Games Studio)

The information in this guide was taken from the manual Div Games Studio, so that everything presented here is compatible, not only with Div GO but also with other Div-like as Gemix Studio, BennuGD or CDiv

Program header Defining comments Statement of global data Statement of local data Statement of private data Main code Blocks PROCESS Blocks FUNCTION

Program header:

PROGRAM <name>;

All programs must start with the keyword PROGRAM followed by the program name and symbol ; (semicolon). This header is mandatory in all programs.

In the names and reserved words are not case-sensitive, so they are valid PROGRAM, program, Program, ...

Example:

Defining comments:

A comment is an explanatory note on the program. Comments are not necessary for the proper functioning of the program.

There are two types of comments:

  - In one line, beginning with the symbol // and end at the end of the line in defined.
  - In multiple lines, beginning with the symbol /* and end with the symbol */.

Example:

Statement of global data:

GLOBAL
   <data declaration>;
   ...

This section of the program is optional; where the data is global in scope, the data can be used from anywhere in the program are declared.

The section must necessarily begin with the keyword GLOBAL followed by a series of data declarations finished with a symbol ; (semicolon).

In general, aggregate data are reported as those who play down general conditions affecting several processes; An example may be the points obtained by the player, which could be stored in the global variable score, so any gameplay could increase it when necessary.

A statement of global data define a unique data that can be used by all processes of the program; instead a declaration will define a local data such data and with that name, for each program processes.

Example:

Statement of local data:

LOCAL
   <data declaration>;
   ...

This section of the program is optional, because this is where the data locally declared, the data that will have all program processes, each with their own values ​​(such as local variables x and y determine predefined coordinates all processes).

The section must necessarily begin with the keyword LOCAL followed by a series of data declarations finished with a symbol ; (semicolon).

In general, local data are reported as those that are considered important information processes, are those who may be interested in consulting or modified from other processes.

An example is the energy that remains for a process (can be a ship, a shot, the protagonist, etc.); this information could be stored in the local variable energy so that any process could access or modify the energy of others (for example, when they collided with power could remove them).

Example:

Statement of private data:

PRIVATE
   <data declaration>;
   ...

These sections are optional programs; in them can declare private data field, data that are to be used exclusively within a process.

This section is defined just before the BEGIN of the process you will use these data and should start compulsorily the PRIVATE keyword followed by a set of data declarations finished with a symbol ; (semicolon).

The main program is also seen as a process, can have your private data statement just before the BEGIN it.

In general, private data are reported as those who will only contain information necessary for a process, they will not be able to be accessed from any other process.

Are defined as private data variables that are to be used as counters in a loop, the variables to contain angles or secondary identifier codes, etc.

Example:
If a data declared as private need for consultation or modified from another process (identifier.data) then this data should be declared as a local (in the LOCAL section of the program); thus, all processes inherit the data, each can access its value or the value of having such data in another process.

Main code:

BEGIN
   <sentence>;
   ...
END

The main program code starts with the keyword BEGIN, which can occur after any number of sentences, and ends with the keyword END.

This code controls the main process of the program, which is responsible for initializing the program, control loops and game menu, and end the program.

Example:
Execution of the main code does not involve complete end program execution, as this process will continue if left alive; If you want to force the termination of the program at the end of this code can be used, for example, let_me_alone() function just before the END which marks the end of the main code to remove the other processes that may remain alive.

It can also be terminated at any point in the program execution by the exit() function that automatically deletes all processes.

Blocks PROCESS:

There are two types of code blocks (besides the main code): the PROCESS block (detailed below), and the FUNCTION block.

PROGRAM <name>;
   <statement of private data>;
BEGIN
   <sentence>;
   ...
END

A process must start with the keyword PROCESS followed by your name and call parameters between parentheses. The parameters are a list of data that the process will receive different values. The parentheses are required even if the process has no parameters.

After this header can come optionally a PRIVATE section where data is declared to be used exclusively by the process.

And finally, the code for the process, which is a sequence of statements between the reserved words BEGIN and END is specified.

A process is normally corresponds to an object type in the game, such as a ship, an explosion, a shot, etc., and in the of the process is often implemented code a loop within which all the necessary values ​​will be set display of that object (graphic, coordinates, etc.) and then, by the FRAME sentence, will order for viewing the object with attributes set.

Example:
As you can see in this example, when you call it a process returns its identifier code (which in the example is stored in the PRIVATE variable id2 of main program); if you want to implement a process-style features from other languages​​, that returns a numeric result, then you should use the RETURN(value) sentence and not use the FRAME sentence in the process, as it returns to the parent (caller) returning the process identifier code as a return value.

Blocks FUNCTION:

The FUNCTION blocks behave analogously to the functions of other programming languages ​​are executed sequentially (not parallel like the PROCESS block), not returning until they have finished.

FUNCTION <name>;
   <statement of private data>;
BEGIN
   <sentence>;
   ...
END

These blocks will still function very similarly to normal processes, but with one important difference: stop the calling process until the end, that is, these functions lie to the process that has been called, until these functions return, or the process ends.

If the function does not use sentences FRAME, it behaves as a normal process, but if a function executes the statement FRAME, will not return to the block that called it (as you would a normal process).

A function can always return a value with RETURN(<expression>), even after giving one or more FRAME.

Sequential programming.

Not recommended to program only with functions and of sequentially form, but knowing how you can facilitate the understanding of programming DIV to programmers from other languages​​.

It is possible to program in the style of traditional programming using the FUNCTION block, only in this way will be a process running at all times exclusively.

When programming this way, the FRAME sentence becomes explicit command to dump video. Logically, if there is only one process running, run this command when the system displays the following image of the program.

But, programming as well, are they might show several graphs on the screen?.

The answer is yes, as this could create a sort of mini-processes that function as an instruction like "paints a graphic to the next picture" (as opposed to functions such as put(), painting a graphic forever).

To display a graph on the following image should build a process that receives visual parameters needed and simply run a single FRAME sentence, for example:

PROCESS painted_graphic(x,y,graph)
BEGIN
FRAME;
END


Calling this process you create a temporary paint process in the image below and then disappears. Other parameters could be envisaged (in addition to x, y, z), as a file, size, angle, z, ... (see the predefined local data).

Programme this way should be created (usually in a global structure) a sprites table so that the program could manage all graphics. While this may seem complicated, it is the natural way to programme games in any other language than is not DIV.

Applications in the main program.

The sentences that appear between the words BEGIN and END of the main program (after data declarations), they control the main process of program. This is responsible for initializing the program, make presentations, menu control loops, loops game (create the necessary processes), and end the program.

In the main program, can be very useful to call FUNCTION block. This will stop the main program while performing the part that controls this function.

For example, the sequence of presentation could be in a function, the options menu in another, etc. Also, remember that the end functions can always return a value to RETURN(<expression>), which can also be useful, for example the menu, return the number of option has been selected.

Note: Finish execution of the main code that does not involve complete end program execution, as this process will continue if left alive; If you want to force the termination of the program at the end of this code can be used, for example, let_me_alone() function just before the END of the main code, or the exit() function (at any point of the program).