Upcoming Events
Unite 2010
11/10 - 11/12 @ Montréal, Canada

GDC China
12/5 - 12/7 @ Shanghai, China

Asia Game Show 2010
12/24 - 12/27  

GDC 2011
2/28 - 3/4 @ San Francisco, CA

More events...
Quick Stats
88 people currently visiting GDNet.
2406 articles in the reference section.

Help us fight cancer!
Join SETI Team GDNet!
Link to us Events 4 Gamers
Intel sponsors gamedev.net search:


 Getting Started
 Loading Your


 Printable version


  The Series

 Doing Something
 Control Structures


Loading Your Scripts

There is no real need to discuss the writing of your script files from VB, as you can simply use notepad or another plain-text editor to do this.

But, loading your script files into your game for use is another story. There are numerous questions which can be asked about how to do this, such as how the lines of 'script' can be parsed into separate pieces, and how to store the scripts while in memory.

User-Defined Types - Gotta Have 'Em!

The first thing to be done is define a user-defined type for a script command line. I suggest placing this into a class module, probably called something such as CScriptParser in order to allow for further expansion in later parts of this series of articles.

Private Type tCmdLine Command As String Parameters() As String End Type

This should be placed in the declarations section of your class module. Another useful UDT that should be created is one for an event block:

Private Type tCmdBlock BlockType As String BlockName As String Commands() As tCmdLine End Type

Storage Variables

To prepare for storing your scripts, you'll need a variable array (put it into your declarations section of the class module you created earlier as well):

Dim CommandBlocks(1023) As tCmdBlock, iLastBlock As Integer

This creates a limit of 1024 possible blocks loaded simultaneously. You can always increase this if you need to. The iLastBlock variable is simply to keep track of the last element in the array which is occupied. You should initialize this variable to -1 when an instance of the class is created, so in the Class_Initialize method of your class, put:

iLastBlock = -1

Next : Actually Loading the Script File