V2 Tutorial
Chapter 01: Neccesary files
The use of these will be clarified later.
Core Engine Files
(3)
Verge.exe -> Runs the game
Maped.exe -> Makes the maps
VCC.exe -> Compiles code
Manditory Files Needed to Run Games
(5)
user.cfg -> Gives VERGE some starting instructions
system.fnt -> Basic font used
system.vcs -> Compiled info
system.idx -> "" ""
trans.tbl -> Used for colours in engine
Files Needed to Run Games
(3+) (Note: Names may change)
console.gif -> Picture used for VERGE console
start.map -> Mapfile opened
start.vsp -> Holds map tile info.
Recomended Files
() (Not neccesary, but useful)
*********
To be added
*********
Chapter 02: File Explanation
VERGE
- The main *.exe file. It first reads user.cfg for startup instructions, and procedes from there. This will run the game.
Maped
- The most important file, it allows you to make the maps from which your game will exist. (See Maped2.txt for details)
VCC
- Reads the corrosponding *.vc file, and compiles the code; thus making it usable by the comp.
User.cfg
- The startup commands of VERGE are here. A simple .txt file changed to user.cfg will do. These lines may be found within the file ( a * represents an optional line):
*log - writes specific data to a file "Verge.log"
startmap blah.map - replace blah to choose the starting map
vidmode x y - Sets the screen resolution, replace x, y with the following, Depending on detail level and video card specs.
300 200
320 240
640 480
sound_device N - Sets the sound configuration, replace N with:
0- Auto detect sound card
1- ?
2- ?
3- Disable sound. Useful when music causes problems.
*mount blah.pck - (Not Sure) reads from a packfile
end - Tells VERGE to stop reading user.cfg.
Here's a sample user.cfg
log
startmap start.map
vidmode 320 240
sound_device 0
end
console.gif
- An image file used for the background of the VERGE console. 320x240 resolution. Should follow the VERGE pallette or it will be very ugly.
Start.map
- The map you created in Maped
start.vsp
- The tiles for the map you created in Maped
start.vc
- Holds map code
system.vc
- Holds system code
Chapter 3: Beginning Programming in VERGE
By now, you should have a map or two. Along with a few characters and maybe a few songs. Quality isn't important here, just something to demonstrate with.
As I am not an expert programmer myself, I won't have the most efficient tutorial on it. I will, however, try to be as clear as I can. To aid this, I will not ramble on about how an integer takes up blah number of bits, and so on.
Sect A: The Simplist of the Simple?
The main piece of information used in VERGE is the int. What an int does is store a numerical value to memory, such as 1 or 6655, or -34, it stores negatives. It will not store decimals, however, so you can't have 6.9 . To declare an int, you use this line...
int name;
The ; (semi-colon) is very important. It essentially tells the compiler that is the end of a command. It must be placed at the end of every command. So, declaring the int is a command in a way. Also, when an int is made, it is set as 0 (zero). To change the value of an int, you simple use an = sign, or perform a mathimatical calculation.
int first; //this makes an int named first
int secnd; //this makes an int named second
int thrd, frth; //this make two ints, thrd and frth. The comma just separates the two.
first=1; //the int, first, holds a value of 1
secnd=first; //this makes second equal to the value of first, or 1.
thrd=secnd+2; //this make thrd equal to secnd+2, or three.
frth=10-secnd+first; //this makes frth equal 10-1+1, or 10.
Not too hard, is it? Basically, it tallies what ever is on the right side of the equal "=" sign, it makes the int on the left equal to it. However, order of operations DO NOT exist. You must use parenthesis for everything.
eg. With order of ops 2+10*2=22
Without 2+10*2=24 you need to have 2+(10*2)
Sect B: Incrementing
Incrementing is basically adding one to a number over and over and over and over and over and over and over and over and over and over and over as long as you want.
first=first+1; //It adds one to first, replacing the old first with the new one.
//It also works like this.
second=second-2; //or thrd=thrd-first; Both of which should be understandable, but if not, here is the rundown.
eg1. second will equal second-2 eg2. thrd will equal thrd-first.
This can all get time consuming after a while, because incrementing is very important. To make things easier, there is this shortcut:
first++; //which is the same as first=first+1; which is easier? It also works the other way.
first--; //or first=first-1;
This does not work for multiplication (Thank god!) or division, the answer would be one.
But what if you don't want to add or subtract 1, you ask.
first+=3; //will add 3 to first. first-=2; will subtract 2 from first.
first+=secnd; //will add second to first.
Well, now you should know basic math crap, as well as how to make ints. That so far means jack-squat. You can't just throw those in anywhere, so I'll explain the use of *.vc files in the first section.
Sect C: System.vc
First of all, if you have downloaded my recomended starting files, you should have an empty file named system.vc. Open it up. (If you have not done this yet, you should see a box asking what to open it with, choose a text program of your choice (notepad, word, textpad... notepad works nicely). In the system.vc, you declare ALL ints, among other things. My main priority for this section is ints, so that will be all I explain at this point. Remember how to declare ints?
int name; or int name1, name2...;
Section A: Comments
Hmmm, comments. Because a coded file may get very long and confusing, the programmer may add comments in that the compiler will ignore, but will be useful in understanding what the hell all the giberish on the screen is. There are two ways of adding comments. Use of 2 slashes // will ignore the rest of the line, ie:
int fagbait; // This int recordes the number of fagbaits?
// What the hell is fagbait??
// int morebait;
OK, the int part should be understandable. The // afterwards denotes a comment, a useful message to yourself, or other coders. The sentence will be ignored. The next line starts with // so the entire line is ignored. They can be added for more messages, telling yourself more details, or suggestions for later. The third line has // and also creates an int. Pop quiz, will the int be made? No, the entire line is ignored, so the compiler will not read that line. This can be helpful in removing a line of code you wish not to use, or isolate if it does not work.
The next comment style works a bit different, and has a different level of uselfulness. This coment starts with a /* and EVERYTHING is ignored until a */, ie:
/* Copyright info:
07/21/00
Blah.
Haha ^_^
*/
This should be understood that everthing between the markers is ignored, even if it spans across multiple lines. This is more usefull if you wish to leave a long message, or remove multiple lines of code with one strike.
Section B: Strings
A string is like an int, but instead of holding a value, it can hold text, numbers, or both. A string is made like an int as well, ie.
String name;
string zug, daboo;
The same as strings, eh? You can't however, have a string AND and int with the same name. When doin' crap with strings, you do it like this:
name="Gerf";
Similar to ints again, but with " "s. Note the semi-colon ; at the end again.
1) // Key greater than 1 >
if(key=1) // key greater than or equal to 1 >=
IMPORTANT NOTE: when the comp tests for a conditional statement, it first reads it and if its true, checks as a 1, if its' false, it checks as a 0. eg. if(key=key) would be '1' or true.
If(1=9) which certainly it doesn;t, it reads as a '0', or false.
These are the main conditions Now that we've tested key, let's make it do something.
if(key=1)
{
// open door
}
else
{
// don't open door
}
This may look a bit funny to you, why I've indented the {, }, and the like. It is very helpful in style. It's not neccesary, but eases a lot in the readability of it. What's easier to read?
if(key>1) if(key>1)
{ {
if(door5) if(door>5)
{ {
// blah //blah
} }
else else
{ {
// more blah // more blah
} }
} }
} }
Although both are fairly wordy, the one on the right should be less confusing as to which If or Else statement starts where. You can see easier which statement is where, and when it ends. Note that it is not neccesary to write this way, but it will be easier if you find a type that suits you becuase you will run into ocasions like this.
if(key=1)
{
if(door=1)
{
// do this
}
}
You should, by now see this tests two conditions before it does this. This is an acceptable way, but there is an easier way, using the double & sign. &&
if(key=1 && door=1) // both must check as a 1 or true
{
// do this
}
Groovy! There is also an easier way of doing this.
if(key=1)
{
// do this
}
if(door=1)
{
// do the same thing
}
By using || or SHIFT \\. It means OR
if(key=1 || door=1) either or both may check as a 1, or true.
{
// haha
}
So there you have it, the IF statement. Not to hard, was it? If you ever feel lost, or cunfused, call this num- no wait. Just re-read the section, or try an if for yourself.
Introduction:
By this point, you should understand the difference between system.vc and map.vc. You should also understand a basic function, and how to use an if statement. If not, feel free to e-mail me (See top) or re-read the section. It only gets easier from here, once you understand the basics.
Sect F: Conditional statements, WHILE
The WHILE loop works a bit differently than IF. It starts the same, While(Key=1) or while(condition to be tested, condition, value).
However, this statement WILL NEVER END as long as the condition is a 1.
eg
event
{
while(1)
{
// do this
}
exit(""); // a command that exits VERGE.
}
The exit will never happen. As I noted earlier, 1 is true, 0 is false. Actually, any non-0 number is true, 1 is the standard. 1, will always read as 1, so will always be true. Since the WHILE loop always reads as 1, it will never end. An if statement will run once if true, a while will never end. This may not seem too useful, so it is more benefietial to do this. The WHILE loop is useful for testing keyboard buttons.
while(key=0)
{
// do a bunch of crap
key=1;
}
When key=1, the condition will no longer be true, so the loop will end. This could be as easy in an IF statement, but it is not easy to show you a useful application this early.
It also can be usedlike this:
while(key etc... And you can compare values to values. While(key>>>>>>>>>>>>>>
>> Sidestep: Chapt -03 Arrays
When dealing with a lot of ints that hold values of similar things, like every treasure box in the game, a more efficient way of dealing with them is through an array. An array looks like this:
int item[999]; // Just like an int, but hold 1000 different values 0-999
and how you use an array is like item[0]=6; or whatever, just like an int. However, another usefull part of arrays is that you can use a variable inside the number, and use it in loopes. eg
for(x=0; x101; x++)
{
item[x]=number;
number++;
}
Not too hard to understand, is it?
The same goes for strings:
string name[15];
Sidestep done
<<<<<<<<<<<<<<<
A little much for one simple thing, especially one that should appear lots in a game. A quicker way of doing this would be to make this a function, or a command of its own. In system.vc is the only plae a function can be declared, or made. Like this:
void name(int first, int second etc...) // name and options of function
{ // should look familiar
} // this too
To declare a function, put void and then the name of the function. Inside the brackets are any intergers you want to make as options for the function. NOTE-The ints and strings declared in the are created when the function starts, and ceases to exist when the function is done.
To go back to our previous example, we could do it like this
void face(int entity_number, int entity_frame)
{
entity.specframe[entity_number]=entity_frame;
showpage
}
and used in a map.vc like this.
face(0, 5); // Changes frame of entity 0 to 5
-oro
face(char, frame); // numbers can always be replaced by variables.
A lot easier, eh?
Chapter 5, Functions as Ints.
There are times when you'll want a function to perfrom some sort of mathematical calculations and store them as an int somewhere. It may look something like this...
/* in system.vc */
int answer
void add(int a, int b, int c);
{
answer=a+b+c;
}
/* in map.vc */
add(12, 23, 5);
damage+=answer;
add(32, 1, 2);
damage+=answer;
what that piece did was add three numbers, added that amount to damage, added three more numbers, and added that to damage. An easier way of doing this would be to make the function=a variable, like an int. To make a funtion an int, you declare it like this:
int add(int a, int b, int c)
{
answer=a+b+c;
}
And then add this line
return answer;
The return basically fills the space with the function being used, with the variable answer.
int add(int a, int b, int c)
{
answer=a+b+c;
return answer;
}
damage+=add(12, 23, 5);
would be the same as damage+=answer;
To go back to the previous example, you could do:
damage+=add(12, 23, 5)+add(32, 1, 2); // The functions are treated like ints
Hopefully this didn't confuse you too much. Basically think of it as an int, taking a final answer from the void.
Chapter 6, Final note on functions.
A few notes on functions, just to clarify things.
-Conditionals can be used in funtions ie. ifs, whiles etc.
-Functions are only made in system.vc or #includes -(see next Chapt)
-Functions can have ints or strings made in them, but only at beginning. Never before a function or command
eg
void blah() // no input needed
{
int a;
int b;
a=b*8+b-a; // just something to fill space.
}
-The ints inside are ONLY used INSIDE, never in an outside command
-Funtions can be nested, or used inside other funtions, eg
void blah()
{
face(0,5); // remember this?
}
Chapter 7, Expanding on System.vc.
If you put every function, void, int, string, etc.. All in one file, that could get very big and messy at the same time. For this reason, you may 'break' the system.vc into multiple files, eg. Battle.vc text.vc mouse.vc etc. To do this, all you do is create a new *.vc file of appropriate name, and put this line in system.vc
#include "blah.vc"
When Vcc encounter this line, it will replace it with the entire blah.vc, making the system.vc a collection of all litte vc files. This will make it much easier to keep organized. You can have as many vc files as you want, all you have to do is #include them. They all have the same allowances as system.vc, eg, make ints, strings, functions.
Something else you can do in system.vc is #Define certain values, which is almost like making an int that can never be changed. For example, if you have multiple loops that all start at the same value, or want to use keywords for maps, chrs, status, blah, blah, blah, Then you can do this:
#Define Normal 0 // all references to normal = 0
#define Dead 1 // dead = 1
#define poison 2 // poison =2
You can have as many as you want, and multiple defines can be the same number, ie
#Define locked 0
#define closed 0
Now for the use
if(door=locked) { dothis(); }
would also work as
if(door=0) { dothis(); }
But what is easier to understand, 0 or locked. Not neccessary, but useful.
Chapter 8, The End.
With the end of this tutorial, there are a couple of errors that MAY be with your version of vcc, and I a couple of tips I believe could be useful
Known Annoyances:
Some Versions of vcc ignore the last couple of lines of your vc file, which could cause some problems. To remedy this, add 4-5 empty lines at the end of your file.
Sometimes when compiling, it may find an error and say system.vc line whatever. It won't clarify if it is on an #include file or not. Just be sure to check that.
This is the bastard error of all time. An error when you have absolutely nothing wrong in the file, and it points errors to empty lines. Maybe also saying a perfectly good function is unknown. This happened to me a few times, with the file compiling, once, and then aftre changing nothing in it, getting an error. My only advice is to look what you did change in the other file, and comment the entire thing out. If it then works, comment a little less out. Eventually you will find what is wrong, probably you spelled something wrong or maybe forgot to put a ;. Maybe you declared an int not at the very beginnning of the function. Lotsa crap coulda happened, but make sure you isolate the problem.
Tips
Use comments to isolate problems.
Use comments to dexcribe what your doing, in case you come back a long time later and don't understand
Misc Comments
Music may really screw the hell outa your game, often ending in a page fault. If you get unknown crashes, remove the music, and then try.
When the code doesn't compile, don't break the monitor. It hurts.
For more clarity on functions, read VergeC.txt and Maped2.txt
When compiling first, use VCC all (as a DOS line) or hit F6 in maped. This will compile system.vc, all #includes, and all map.vc.
E-Mail me TheGerf@hotmail.com if you ever have some bastardly error, or need some help. I will try to help you, explain how something works, or point you in the right direction.
***********************************************************************
This concludes TheGerf's Verge2 tutorial for the beginner.
Please send all questions, comments, concerns to TheGerf@hotmail.com