Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Source Guide


Helladen
 Share

Recommended Posts

I will be explaining to all of you the basics of Visual Basic 6 programming and various things to help you understand the source better.

**IDE Basics:**
>! First of all, you must learn the interface.
>! **Project & Properties Window**
The project window displays all your source items such as forms and modules. Properties window is used in modifying the properties in a form. My advise is to keep the project and properties windows open and clip them on the right side of the screen. (Top project explorer and bottom properties window).
>! **Immediate Window:**
To be honest, the immediate window seems worthless to me. Never have used it once, but it is used for displaying print screen messages using debug.print. It is handy for camera testing and such, but for most sourcing it will have no use. My advise here may be wrong, because I have not used it so be warned.
>! **Tools:**
These enhance and add more control to your forms, you can add your own if your an experienced Visual Basic 6 programmer by making a component. You can locate them on the left side of the IDE, you click on the button you want to use. You click where you want to place it on the form and by dragging it will resize how large it will be.
>! _Tip: They are referred as user controls_
_Tip: When you place something on a frame it will snatch to it, meaning you can't move it off of it until it is erased. So if you have issues with your things getting stuck on frames when you don't want them to, just erase and place it in a different spot away from the frame._
>! **References:**
These are defined libraries the project uses. (.olb, .tlb, and .dll)
>! **Components:**
They are user control tools which are made using ActiveX, such as labels and text boxes.
>! _Tip: References and components are only for advanced Visual Basic 6 programmers._
>! **Public & Private:**
Private means it can only be called within the area it is at, for example if I make a private sub in modCombat it can only be called from a sub or function from this module. Public means it can be called globally.
>! **Forms:**
They are the visual part of your project. Something that allows you to interact with your code.
>! _Tip:_ To call things from outside of forms you must type the name of the form then a period then the sub or function.
>! **Modules:**
They are sort of a fancy name for a folder. They allow you to store code into them that can be made public or private.
>! **Classes:**
They are an advanced way of initializing data. Primarily good for systems used a lot, because they are nice and clean to use. Such as a sound engine would be good to be a class, because you can initialize it and turn it off very easily. An example of a class is the clsBuffer, which is the only class found in Eclipse Origins.
>! **Add-on:**
The best improvement to the Visual Basic 6 IDE is an extension called CodeSmart which will enhance and fix various bugs with it. This costs a lot of money, so your best chance at using it is the free trial and if you like it enough buy it.

**Coding Basics:**
>! **Calling a Sub or Function:**
You do not need to put "Call" in front of code for it to call, it will automatically execute everything. Call just makes it look cleaner because it will add brackets around it and make it more compact.
>! **Functions and Subs:**
Functions will return data back from where they were called just like if you use ByRef on a constant in a parameter header. Subs will not return data.
>! **Useful Functions:**
_Tip: Always use the first one, the second one is much slower._
_Tip: You must put brackets around the area you want the function to affect._
>! Trim$/Trim: This will get rid of blank spots around the string.
Len: This will return the length.
LenB: This will return the value in bytes.
Dir$/Dir: This will return the name of the directory.
ByVal: Any changes made to the variable are not returned to the calling procedure.
ByRef: Any changes made to the variable are returned to the calling procedure.
>! **Constant Types & Other Useful Terms:**
Vbnullstring: Means null, an empty string.
Byte: 0 through 255, this can't be negative.
Integer: -32767 through 32767.
Long: -2147483647 through 2147483647.
String: This is a text constant, it has no limit it can be as long as the memory will let it go. So you must put a limit on it yourself. Sometimes you'll be able to get away with it, but it's advised to always use * and the length you want it to be. This will cause you to have to use Trim$, but it will save you loads of memory.
Single - Limited to 7 digits. (4 bytes storage required).
Double - Limited to 15 digits. (8 bytes storage required).
>! **Arrays:**
These are matrices, which hold multiple values. An example of how to use an array can be seen with Player(1 to MAX_PLAYERS), each value inside of here holds the player's data.
>! **Visual Example of an Array:**
>! >! [1][0][2]
[3][0][1]
[1][4][5]
**Enumerations:**
They are a list of names used to define numbers.
>! _Tip: Packet header/first thing written to it is an enumeration._
>! **Types**
They are a collection of variables.
>! _Tip: PlayerRec is considered a type._

**More Advanced:**

>! **Networking:**
WinSocket is a very easy to use networking tool. Jacob programmed the clsBuffer which is the foundation of the packets that are read and sent. Both the client and server clsBuffer are exactly the same or should be. To use this is very simple compared to the old way it was done in Mirage Source 3.
>! Sockets are opened and closed whenever a player joins and leaves the game. Winsocket has a few issues with this because it requires you to call DestroyTCP or send a packet which is how Eclipse Origins does it. (Packet is a waste because all you need to do is DestroyTCP). A socket will remain open even if it is not receiving a connection. It must be closed in order for it to show that the player has actually logged out. You can force close it by calling CloseSocket in the server though. The only time this would become a problem is if the client was force closed or you lost internet while logged in.
>! First of all you should preallocate the values before you send them. Preallocating will speed up the sending slightly. (Bytes are 1, integers are 2, and longs are 4). An example of how to preallocate is to put it before you write anything and put Buffer.Preallocate then the added up number.
>! Both the writing and reading of the data should match exactly. I'll give you an example of how to how to use the clsBuffer. You can look at the comments inside the code I left to explain what each thing does.
>! ```
Sub SendMapReport()
    Dim Buffer As clsBuffer ' This is the constant we use to know what the clsBuffer is

    ' If debug mode, handle error then exit out
    If Options.Debug = 1 Then On Error GoTo errorhandler

    Set Buffer = New clsBuffer ' This will initialize the class.
    Buffer.WriteLong CMapReport ' This will write the enumeration header for the packet.

    SendData Buffer.ToArray() ' This will send the packet to the server.
    Set Buffer = Nothing ' This will turn off the class.
    Exit Sub

' Error handler
errorhandler:
    HandleError "SendMapReport", "modClientTCP", Err.Number, Err.Description, Err.Source, Err.HelpContext
    Err.Clear
End Sub
```
You can trace where this is sent by going into the server and finding "CMapReport" in modHandleData.
>! _Tip: C stands for client and S stands for server. This is an indication where it came from._
_Tip: CopyMemory is slower than actually sending the code over using packets from caches. To learn how to use a cache to send as a packet simply look at SendMap, HandleMapData, and MapCache() array in the server. The client uses HandleMapData and SendMap._
>! **How To Use Types:**
When we use types, we're basically organizing it. There are many contributions that this helps such as clearing, saving and loading too.
>! An example of a type being used:
```
If Player(Index).Level = 1 then
```
This will get the player's level which is one, by doing this you can compare values easily. The main thing about using types is understanding how to get the correct slot for the array.
>! Now time to explain how to use the npc types, which are a bit trickier to use.
```
If Npc(MapNpc(MapNum).Npc(MapNpcNum).Num).Level = 1 Then
```
This will get the level of the map npc which is one. This uses two defined constants to find the slots of the arrays within the type. MapNum usually will be GetPlayerMap(Index), but if the sub does not have a player, it must be predefined from a source outside the sub or function, or in the parameter header of the sub or function (MapNpcNum too). The main thing about this is keeping data flowing correctly through many different subs and functions, it starts off defining the value and you must keep it moving until it is no longer needed.
>! The NpcRec is a type which holds the npc's data, the .Num part of the code is a stored value of the npc's number so it can tell which data it should use from the npc editor. MapNpcRec is a type which holds the map npc's data. Map npc data is basically altered states, such as how much health they have left.
>! **Binary:**
These types of data storage work well with types, you can export and import data very quickly. You first have to clear the type out completely, then load it using the binary file and save it if it is modified.
>! ```
    Open FileName For Binary As #F ' This opens the binary file by the path specified.
        Get #F, , Item(ItemNum) ' This will put the binary file's data into the ItemRec of the item number specified.
    Close #F ' This will close it.
```
```
    Open FileName For Binary As #F ' This opens the binary file by the path specified.
        Put #F, , Item(ItemNum) ' This will put the ItemRec of the number specified into the binary file.
    Close #F ' This will close it.
```

**Modules:**

>! This will explain to you what each module in Eclipse Origins primarily does.
>! **Both:**
modConstants - This holds all constants that are given a base value automatically.
modGlobals - This holds all constants that are given a value within the code itself.
modDatabase - This is where all the database code is placed that has anything to do with clearing, saving, loading or searching for files.
modEnumerations - This is where all enumerations are placed. If you don't know what they are look above.
modTypes - This is where all types are placed, if you do not know what a type is read above.
modGameLogic - This is where all the logic for the game is placed.
modGeneral - This is where general things are placed which do not fit into the other modules.
>! **Client:**
modClientTCP: This handles the client WinSocket and packets that are sent to the server.
modDirectDraw7 - This is where all the DirectX/rendering code is placed.
modGameEditors - This is where all the game editor code is placed. Such as initializing the editors, requesting to use them, and saving modified files.
modHandleData - This is where receiving packets are handled from the server.
modInput - This is what handles controls and key presses.
modText - This is where all code which has to do with text.
>! **Server:**
modServerTCP: This handles the client WinSocket and packets that are sent to the client.
modHandleData - This is where receiving packets are handled from the client.
modPlayer - Subs and functions which affect the player and do not serve any other purpose.
modCombat - This serves to handle all code which affects combat.
modSysTray - This handles shell code.
modServerLoop - This is like GameLoop sub on the client, but it is its own module on the server. It handles the looping process of the server for many calls and functions which are given a timer to when they are to be called again. All code which is intended to be looped should be placed in here.
If you liked my guide just say so below and I will add more. Hopefully this was helpful. :)
Special thanks to a friend of mine, he helped me with a few terms and preallocating values. I am very bad at terminology.
Link to comment
Share on other sites

Thanks for the comments. I reorganized some of the text and added tools in IDE Basics and some other minor additions.

@Willa56Seidenberg:

> You should try out something more precise, as many far more better tutorials are available to learn VB 6.

This is just a basic guide, not meant to teach you everything.
Link to comment
Share on other sites

@Willa56Seidenberg:

> You should try out something more precise, as many far more better tutorials are available to learn VB 6.

exactly.  People can learn VB6 from there.  This will teach people how to code EO (though it isn't too helpful yet, only the basics of basics have been covered.)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...