The VERGE 2 Manual

The reference manual for the VERGE 2 and WinV2 game creation engines. No longer in development, but someone out there may benefit from this!

Variables

Integers

Integers hold non-fractional numerical values. An "int" can have a value from -2,147,483,648 to 2,147,483,647.

int an_int; //this creates an int named 'an_int'
int another_int; //this creates another int.

an_int = 5; //this sets it to the value 5.
another_int = 3; //another_int is now equal to 3.

another_int = an_int; //another_int is now equal to 5.

an_int = 7; //an_int is now 7, but another_int is still 5.

The verge integer is 32 bit, here's a detailed run down of what that means:
In a 32 bit integer, there are 32 bits than can be either on or off
This is 2^32 combinations, or 4294967296
Binary numbers: 0 1 0 1 1.....0
Equivalent to: 2^0+2^1+2^2+2^3+2^4...-2^31
Which is: 1 + 2 + 4 + 8 + 16....-2147483648
Why is the last number (bit) negative?
So we can store all the negative numbers easily as well.
Then it is still just case of adding to bits to get the number.
Note that as 0 has to be stored as well, there is one less positive than negative
So in a 32 bit int, the number can be between -2^31 and 2^31-1
Alternatively in decimal from -2147483648 to 2147483647
Eg. The number 13 is stored as 8+4+1 or 1011000...0
The number -13 is stored as -2147483648 plus everything BUT 8+4 so 11001111...1
Note that the +1 is still on, as negative numbers stretch one lower than positives
Because the top bit is negative, in an overflow case (trying to store to large a number) you will 'wrap around' and get a negative number.

Strings

Strings hold phrases of text in them.

string your_name; //this creates a string named 'your_name'

your_name = "mud"; //this sets your_name to the value 'mud'

Is a string a fixed number of characters?

Yes. You may only have up to 255 characters in a string.

Arrays

You can declare arrays of both ints and strings. You can only declare them in SYSTEM.VC (and any #included sub-files). Variables declared outside of any function are global and can be accessed by any system.vc OR map-based VC event at all. Arrays must be global.

Example:

int flags[8000];

Language Specification

Operators

For those of you familiar with C, I'll give you a quick rundown (everyone else skip this paragraph): VERGE has pretty much all the C operators you'll need except pointer stuff. It has no order of operations. There's no *=, /=, or %=, but there is a += and -=. The assignment operators do not return values and as such cannot be used inside an arithmetic or logical expression. Logical operators can't be used in arithmetic expressions. There's no bitwise NOT. You can't use assignment operators in logical or arithmetic expressions. Since all integers are signed, bitshifting is automatically signed as well. You can't use parentheses to change the evaluation order of a logical expression.

Verge contains five kinds of "operators" used to build statements. An operator is a symbol which, when combined with one or more "operands" (constants, variables, or expressions), changes the value of the operands or produces a new value based on them. For example, the + arithmetic operator takes two integer operands and produces a new integer which is the sum of those two.

Operators are either unary or binary; that is, they take either one or two operands. Unary operators either precede or follow their operands, whereas binary operators have are placed in between their two operands. The + operator mentioned above is binary, so its operators are placed on either side; to produce the sum of 5 and 6, we type "5 + 6". Except where otherwise stated, all the operators described below are binary.

ARITHMETIC OPERATORS:

The arithmetic operators represent fundamental mathematical operations such as addition and subtraction.

Addition (+): The addition operator generates a new number that is the sum of its operands.

Subtraction (-): The subtractio operator generates a new number that is the difference of its operands. Order is important; the operand after the minus sign is subtracted from the one before it.

Multiplication (*): The multiplication operator generates a new number that is the product of its operands.

Division (/): The division operator generates a new number that is the quotient of its operands. As with subtraction, order is important; the first operand is the numerator, the second the denominator. This is integer division, which means that the final value is always an integer, rounded down if necessary.

Modulus (%): The modulus operator returns the remainder of the division of the first operand by the second.

Arithmetic operators can be combined into complex arithmetic expressions. They are evaluated from left to right; that is to say, there is no order of operations. To enforce a specific evaluation order, you may use parentheses.

// Arithmetic Operator examples
int n = 0;      // n starts out as 0

n = 2 + 3;      // Addition: n is now 5
n = 12 - n;     // Subtraction: n is now 7
n = 2 * 4;      // Multiplication: n is now 8
n = n / 2;      // Division: n is now 4
n = 10 % 3;     // Modulus: n is now 1 (the remainder of 10 / 3)

// Examples of complex expressions

n = 1 + 3 * 5;                    // n is now 20 (since there's no order of operations)
n = 100 % (9 * 3);                // n is now 19 (the remainder of 100 / 27)
n = 2 * (5 - (7 * 3));            // n is now -32

BITWISE OPERATORS:

Bitwise operators are so called because they operate individually on every bit of a (32-bit signed) integer. Because they manipulate numbers on a binary level, they are somewhat tricky for beginners. If you feel comfortable with them, however, you can use bitwise operators freely in arithmetic expressions.

Bitwise OR (|): The Bitwise OR generates a new value by ORing each bit of the two operands. What this means is that the new value will have a 1 in each bit location where either or both of the operands had a 1, and a 0 in every other bit location.

Bitwise AND (&): The Bitwise AND generates a new value by ANDing each bit of the two operands. What this means is that the new value will have a 0 in each bit location where either or both of the operands had a 0, and a 1 in every other bit location.

Bitwise XOR (^): The Bitwise XOR generates a new value by exclusive-ORing each bit of the two operands. What this means is that the new value will have a 1 in each bit location where either one or the other but not both of the operands had a 1, and a 0 in every other bit location.

Left Bitshift (<<): The Left Bitshift operator generates a new number which is its first operand with all the bits shifted left a number of spaces equal to the value of the second operand. If this sounds confusing, here's an easier way to think about it: in the expression m<Right Bitshift (>>): The Right Bitshift operator generates a new number which its its first operand with all the bits shifted right a number of spaces equal to the value of the second operand. In the expression m>>n, the value returned is equal to m divided by 2 to the nth power (using integer division, naturally).

LOGICAL OPERATORS:

The logical operators can be used only in the conditions of if and while statements. They return either true (a nonzero number) or false (zero). Like arithmetic operators, logical operators take integer variables, constants, or expressions (arithmetic or logical) as their operands, and are evaluated from left to right. However, as of this writing, you cannot change the evaluation order of a logical expression using parentheses.

Equality (==): The Equality operator returns true if the two operands are equal; otherwise, it returns false. It is represented as a double equals sign to differentiate it from the Assignment operator (which see). Note that neither strings nor structs can be used as logical operands, so this operator cannot be used to test their equality.

Inequality (!=): The Inequality operator returns true if the two operands are inequal; otherwise, it returns false.

Greater Than (>): Greater Than returns true if the first operand is greater than the second; otherwise, it returns false.

Lesser Than (<): Lesser Than returns true if the first operand is lesser than the second; otherwise, it returns false.

Greater Than or Equal To (>=): Greater Than or Equal To returns true if the first operand is greater than or equal to the second; otherwise, it returns false.

Lesser Than or Equal To (<=): Lesser Than or Equal To returns true if the first operand is lesser than or equal to the second; otherwise, it returns false.

Logical OR (||): The logical OR returns true if either or both of its operands are true; otherwise, it returns false.

Logical AND (&&): The logical OR returns true only if both of its operands are true; otherwise, it returns false..

Logical NOT (!): The logical NOT is a unary operator that precedes its operand. It returns true if its operand is true; otherwise it returns false.

Note that there is no logical XOR in VERGE.

ASSIGNMENT OPERATORS:

Assignment operators are special in that they actually change the value of one of their operands. The operand to be changed must be a variable, since only variables can have their values altered. Assignment operators are also unique because they do not return values; for this reason, they cannot be used inside expressions.

Assignment (=): The ordinary assignment operator changes the the value of the first operand to the value of the second.

Increment (++): Increment is a unary operator that follows its operand. It increases the value of its single operand by 1.

Decrement (--): Decrement is a unary operator that follows its operand. It decreases the value of its single operand by 1.

Increase (+=): The Increase operator increases the value of the first operand by the value of the second.

Decrease (-=): The Decrease operator decreases the value of the first operand by the value of the second.

The ordinary assignment operator (=) can be used within a declaration statement to initialize a newly declared variable to a specific value.

// Assignment operator examples
int n = 2;        // n is declared and assigned the value of 2
n = 7;            // n is assigned the value of 7
n++;              // n is now 8
n--;              // n is now 7 again
n += 12 + n;      // n is now 26
n -= n;           // n is now 0

STRING OPERATORS:

There are only two string operators in VERGE. They accept only string variables, string literals, and functions that return strings as their operands.

String Concatenation (+): The string concatenation operator is the plus sign, just like the addition operator. Since the operator is preceded by its first operand, the compiler figures out whether it's doing addition or concatenation by looking at the type (int or string) of that operand. Concatenation produces a new string composed of the second operand appended to the first.

String Assignment (=): The String Assignment operator is identical to the ordinary assignment operator, except it functions on strings rather than integers.

// String concatenation examples
string s = "";                     // s is declared and set to an empty string
string s = "hell" + "o";           // s is now "hello"
string s = "why " + s + " there";  // s is now "why hello there"

Note: You can't do these togther with the += operator.

string s = "Fish";
s += " and Chips"; // NOT valid
s = s + " and Chips"; // Use this instead

Comments

Just as in VC1, both C and C++ style comment conventions are supported.

Comments: Comments are not required in your VergeC code, but smart event coders will use them to help organize and make their event scripts readable for future reference. They are ignored by the compiler. There are two ways to use comments:

The // is preferred for simple phrases that you wish commented, while the /* */ method is best for large areas of text to be left commented.

NOTE: Try using commenting if you have a problematic area of your event script that refuses to compile. Use // before the lines that create errors and try recompiling until you can isolate the problem.

Control Structures

VergeC 2.0 supports most of the code control structures that genuine ANSI C does, with some differences that are explained below:

System and Map Code

There are two distinct types of VC in V2, and that is the system.vc, and everything else, which are MAP-based VC files. MAP based VC is very similar to how VC was in V1. You cannot declare your own functions or variables in a MAP vc. They use the familiar event { } style scripts. When they are compiled their pcode is attached directly into the MAPfile itself.

The other type is system.vc, which is compiled into the files system.vcs and system.idx, respectively. system.vc allows you to declare your own functions and variables - the trick comes in that any of your map VC can access any and all of the functions and variables set up in system.vc.

The only real problem arises that, because of the new relationship between system.vc and map-based VC, it's conceivable (quite likely, actually) that if you modify system.vc you'll break MAPs that you've already compiled. As such, VCC now has a 'vcc all' option, that will compile system.vc, and then recompile all maps it can find in the given directory. ME2 has a shortcut to do this right from inside MapEd - Just hit F6 and it'll rebuild all of your VC files. (of course, this means you can't have an ALL.MAP. Oh well, live with it. ^_-)

There is nothing like startup.vc or startup.scr in V2. When you execute verge.exe, it always starts execution at a MAP file. Which mapfile it starts at is determined in user.cfg, by the 'startmap' command. Additionally, you can start verge.exe at a specific map by specifying the mapfile on the command line, which MapEd makes use of to directly test out the mapfile you're currently working on.

Functions

There are two types of user declared functions, ones that return a value and those that don't. The simplist declaration for a function would be:

void MyFunc()
{ }

You can add passed parameters like so:

void MyFunc(int a, string b)
{ }

These parameters would be accessed inside this function as any other variable would be, but it only exists inside the function. You would call this function from map or other system.vc code with something like this:

MyFunc(5, "Hello.");

To make your function return a value, you'd declare it like so:

int MyAdd(int a, int b)
{
  return a+b;
}

You can now return strings as of 4.4.00 Version 2.5. Very useful:

string my_routine(int a, string b)
{
  int this;
  string that;
  return that + b;
}

Limits of passed parameters and local variables: For any given system.vc function, the total number of passed parameters and local variables cannot exceed 20, and the total number of passed and locally declared strings cannot exceed 10. However, if you have 10 strings, you can only have 10 ints, otherwise the total limit of 20 variables (int and otherwise) would be exceeded.

If there is a global variable and local variable of the same name, inside the function the local variable will be used instead. But in a function where that local var isn't declared, or a map-vc event, the global variable will be used instead.

Preprocessor Directives

Preprocessor directives are special statements that begin with a pound # sign, and are the only ones that don't need the semi-colon ; at the end.

Preprocessor directives must be in a linear order, and BEFORE the code to keep certain errors from coming up.

There are two important directives:

Engine

USER.CFG

The following are the available User.cfg commands to Verge 2:

mount (filename)  Mounts the specified .VRG packfile.
vidmode (xres) (yres) Sets screen resolution
log     Turns logging on.
startmap (filename) Chooses starting map
sound_device (0 - 3)  0 = autodetect, 3 = nosound
mixrate (frequency) Mixrate of sounds.
dmabufsize (size) ???
force8bit   Forces 8-bit quality sound output
forcemono   Forces monaural sound output
end     Denotes the end of the .CFG.

The following are the available commands to WinV2:

xres, yres          Pretty self-explanitory.
windowmode (0, 1)   Toggles fullscreen/windowed mode.
nosound (0, 1)          Toggles sound playback
eagle (0, 1)            Toggles the 2xSAI (yes the name is confusing) filter
paranoid (0, 1)         Toggles strict VC runtime error checking
arraycheck (0, 1)       Toggles VC array range checking, see above
appname (name)          Sets the name shown in the Window title
mount1 .. mount3 (file) Mounts the specified .VRG packfile.

Debug Console

Note: WinV2 does not have a console menu.

                     ===================================�
                     =    V2 Console Command Summary    =
                     ====================================
Current as of 5.9.99

Using the Command Console
================ ====== ==== == =
The command console is summoned by the ~ (tilde) key. Pressing the same key
a second time hide the console as well. If ~ does not bring the console down,
the game designer has disabled it via the AllowConsole(0); call.

You basically use it by just typing commands into it. The actual commands will
be detailed below. However, in addition to typing commands, it also supports
the following features:

  The UP/DOWN keys are a 10-entry Last Command Memory.
  The PGUP/PGDN keys allow you to use the scrollback features.
  TAB is command-name completion.

Console Command Reference
================ ====== ==== == =
========================================================================�
= ACTIVEENTS = Parameters: None                                         =
============== Usage: ACTIVEENTS                                        =
= Description: Lists the index numbers of all active (onscreen)         =
=  entities.                                                            =
=========================================================================
========================================================================�
= BROWSETILES = Parameters: None                                        =
=============== Usage: BROWSETILES                                      =
= Description: Displays the tileset currently loaded. Inside the browse =
=  interface, the up/down keys scroll through the tiles if there are    =
=  more than fit on the screen. The A key toggles tile animation, Q     =
=  exits the browse interface.                                          =
=========================================================================
========================================================================�
= CAMERATRACKING = Parameters: [on/off]                                 =
================== Usage: CAMERATRACKING [0/1]                          =
= Description: If CAMERATRACKING is executed with no parameters, the    =
=  status (0 or 1) will be returned. If 0 or 1 is specified as the 1st  =
=  parameter, that will set a new value for cameratracking. This        =
=  variable controls whether or not the camera follows the player       =
=  around at all times.                                                 =
=========================================================================
========================================================================�
= CD_OPEN  = Parameters: None                                           =
= CD_CLOSE = Usage: CD_OPEN                                             =
============ Usage: CD_CLOSE                                            =
= Description: Opens or closes the CD tray door, respectively.          =
=========================================================================
========================================================================�
= CD_PLAY = Usage: CD_PLAY                                    =
= CD_STOP = Usage: CD_STOP                                              =
=========== Description: CD_PLAY begins CD audio playback at the        =
= specified track number. CD_STOP stops all CD audio playback.          =
=========================================================================
========================================================================�
= CONSOLEBG = Parameters: None                                          =
============= Usage: CONSOLEBG                               =
= Description: Sets the specified image as the console background. The  =
=  image can be in PCX, GIF or BMP format, but must be 320x240.         =
=========================================================================
========================================================================�
= CPU_USAGE = Parameters: [on/off]                                      =
============= Usage: CPU_USAGE [0/1]                                    =
= Description: Turns on or off the CPU usage monitor. When it's on, it  =
=  displays an FPS report and shows CPU usage in the categories of      =
=  rendering, pageflipping, and game ai (etc).                          =
=========================================================================
========================================================================�
= CURPOS = Parameters: None                                             =
========== Usage: CURPOS                                                =
= Description: Returns the current coordinates of the player.           =
=========================================================================
========================================================================�
= ENITITY = Parameters: [index]                                         =
=========== Usage: ENTITY [ent num]                                     =
= Description: Returns the current coordinates of the given entity.     =
=========================================================================
========================================================================�
= ENITITYSTAT = Parameters: None                                        =
=============== Usage: ENTITYSTAT                                       =
= Description: Gives a report on the current entity stats.              =
=========================================================================
========================================================================�
= EXIT = Parameters: None                                               =
======== Usage: EXIT                                                    =
= Description: Exits to DOS.                                            =
=========================================================================
========================================================================�
= LISTCMDS = Parameters: None                                           =
============ Usage: LISTCMDS                                            =
= Description: Lists all registered console commands.                   =
=========================================================================
========================================================================�
= LISTMOUNTS = Parameters: None                                         =
============== Usage: LISTMOUNTS                                        =
= Description: Lists all currently mounted packfiles.                   =
=========================================================================
========================================================================�
= MAP = Parameters: [MAP name]                                          =
======= Usage: MAP [MAP name]                                           =
= Description: MAP with no parameters gives a statistics report about   =
=  the currently loaded MAP. Otherwise, it will attempt to map switch   =
=  to the map file specified.                                           =
=========================================================================
========================================================================�
= MOUNT = Parameters: [Packfile]                                        =
========= Usage: MOUNT [packfile name]                                  =
= Description: MOUNT will mount the specified packfile and add it to    =
=  VERGE's packfile search list.                                        =
=========================================================================
========================================================================�
= PACKINFO = Parameters: [Packindex]                                    =
============ Usage: PACKINFO [packindex]                                =
= Description: Packinfo returns a list of files and in a given packfile.=
=  To view the first packfile mounted, you would type "packinfo 0".     =
=========================================================================
========================================================================�
= PHANTOM = Parameters: [On/Off]                                        =
=========== Usage: PHANTOM [0/1]                                        =
= Description: Turns on or off Phantom mode (no clipping)               =
=========================================================================
========================================================================�
= PLAYER = Parameters: [Entity index]                                   =
========== Usage: PLAYER [idx]                                          =
= Description: Sets the player to the given entity number.              =
=========================================================================
========================================================================�
= PLAYERSPEED = Parameters: [speed]                                     =
=============== Usage: PLAYERSPEED [1-7]                                =
= Description: Sets the player speed                                    =
=========================================================================
========================================================================�
= SHOWOBS = Parameters: [on/off]                                        =
=========== Usage: SHOWOBS [0/1]                                        =
= Description: If this is turned on, grid will be drawn on top of the   =
= render process denoting where the obstruction are on the map.         =
=========================================================================
========================================================================�
= SHOWZONES = Parameters: [on/off]                                      =
============= Usage: SHOWZONES [0/1]                                    =
= Description: If this is turned on, grid will be drawn on top of the   =
=  render process denoting where the zones are on the map, color coded. =
=========================================================================
========================================================================�
= SPEEDDEMON = Parameters: None                                         =
============== Usage: SPEEDDEMON                                        =
= Description: This command will enable the "2x speed" cheat to allow   =
=  the player to move twice his normal velocity when the CTRL key is    =
=  held down.                                                           =
=========================================================================
========================================================================�
= VER = Parameters: None                                                =
======= Usage: VER                                                      =
= Description: Displays a V2 version report and build info.             =
=========================================================================
========================================================================�
= WARP = Parameters: [tile-x, tile-y]                                   =
======== Usage: WARP [x] [y]                                            =
= Description: Warps the player to the specified location.              =
=========================================================================

Special Commands: RV/SV
================ ====== ==== == =
These two additional console commands are extremely useful in the development
and debugging of your Verge game, especially with advanced VC. These commands
stand for ReadVariable and SetVariable, respectively; they allow you to access
the value of any user declared (system.vc global) variable (ints only, not
strings). You can access both single ints and array components.

For example, to read the value of a variable named "gold" you'd simply do:
RV GOLD
and the value of the variable would be printed out. To set the value of "gold"
to a really big value, you'd type:
SV GOLD 1500000

To use array variables, you simply add another parameter which is the array
offset, ie:
RV FLAGS 105
Would return the value of flags[105]. Likewise, to set the value of flags[20]
to 0, you'd type:
SV FLAGS 20 0

Have an idea for a console command you'd like to see implemented? Mail me
at aen@verge-rpg.com and We'll consider your request.

- Verge2 staff

Function Reference

General Utility Functions

AllowConsole

void AllowConsole (int flag)

Controls whether or not the ` key will summon the console or not.

Example usage:

AllowConsole(1); // Enable the console!

Controls whether or not the ` key will summon the console or not. 0 will disallow the console, 1 will activate it. Disabling the console is a good way to prevent cheating, however having it enabled will make developing and testing the game easier.

Note: This is function deprecated in WinV2. Having it in your code will cause it to be ignored.

CallEvent

int CallEvent (int which_event)

Calls the specified map event.

Example usage:

CallEvent(3);

Calls the specified map event.

Exit

void Exit (string message)

Exits Verge.

Example usage:

Exit("Thank you for playing!");

Completely exits out of the engine leaving the user with the specified message.

HookKey

void HookKey (int scancode, system script)

Binds an event to a specified keypress.

Example usage:

HookKey(1, Menu); // When Escape is pressed (key scancode 1), the function Men() in system.vc will be executed.

Binds an event to a specified keypress. This allows you to create menus and other types of key-based events easily.

HookRetrace

void HookRetrace (system script)

Execute the given VergeC event every render.

Example usage:

HookRetrace(my_script); // hook script
HookRetrace(1); // hook event

Given a non-zero event number, it will execute the given VergeC event (from the Map VC) each time a frame is rendered. Note that it will be called at the 'R' position in the Renderstring, so if there *is* no 'R' position, then it will never be executed. As in verge 1, HookRetrace is quite stable, and should be used instead of HookTimer whenever possible. You can pass zero to this event to turn off the HookRetrace.

HookTimer

void HookTimer (system event)

Executes a VC event each time tick.

Example usage:

HookTimer(my_script); // hook script
HookTimer(1); // hook event

Given a non-zero event number, it will execute the given VergeC event (from the Map VC) each timer tick (ie, 100 times per second). Note that, like verge 1, this is the more volatile of the Hook* family of functions, and HookRetrace should be used in place of HookTimer whenever possible. When using HookTimer, you should never call any rendering functions, and in general you should do as little as possible inside the hooked event as you can. As with HookRetrace, passing 0 to this function will turn off the HookTimer.

Log

void Log (string text)

Outputs a message to Verge.log

Example usage:

Log("VERGE 2");

Outputs a message to Verge.log (WinV2.log on WinV2), assuming verge.log is enabled by the user. This can be useful for debugging.

Message

void Message (string message, int duration))

Issues the specified system message.

Example usage:

Message("VERGE 2", 200);

Issues the specified system message, lasting the given duration in hundreths of a second. This message is displayed in the upper left corner of the screen for the given duration, and noted in the verge.log file.

Note: This is function deprecated in WinV2. Having it in your code will cause it to be ignored.

Random

int Random (int range)

Returns a random number between 0 and the range given.

Example usage:

if (Random(100) < 50)
{
  PrintString(0, "Heads!");
}
else
{
  PrintString(0, "Tails!");
}

Returns a random number between 0 and the range given.

ReadMouse

void ReadMouse ()

Updates the mouse status variables.

Example usage:

ReadMouse();
Updates the mouse status variables mx, my, and mb.

SetMousePos

void SetMousePos (int x, int y)

Sets the current mouse position.

Example usage:

SetMousePos(screenx/2, screeny/2);

Sets the current mouse position to the given x and y coordinates. Does no checking to make sure the coordinates are valid, so check that yourself, they should between 0 and screenx and 0 and screeny, respectively.

Note: This is function deprecated in WinV2. Having it in your code will trigger an error.

SetResolution

int SetResolution (int xres, int yres)

Sets the video mode to the specified resolution.

Example usage:

SetResolution(320, 240);
Sets the video mode to the specified resolution. Returns 1 if successful, 0 if the mode set failed. As of 4.4.00 V2.5 supports any 256-color resolution. Common video modes: