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
63 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:


 Command Blocks

 Printable version


  The Series

 Doing Something
 Control Structures



This is the second part in this series of articles on one of the most important parts of a game (especially an rpg): scripting. In the first part, I discussed the general concepts of scripting, and how to store/read/write your script files.

In this second part the actual implementation of the scripts will start to be discussed in some detail, paving the way for the third part where I will go much deeper into some commands that you should have in your engine no matter what type of game (ie: decision-making, loops, etc).

Two Possibilities...

After much thought, two obvious options for the implementation of the scripts occurred to me. The first one is probably the simplest: use a giant Select...Case statement to choose which functions to call, etc. The problem with this method, though, is that it rapidly becomes very confusing, and much slower the more commands that you have.

The second option that I came up with uses a new method introduced in VB6: CallByName. This function will allow you to call any sub/function/property of an object by passing it's name as a string. If you think about this in the context of scripting, you will realize that we already have each command that needs to be executed for our script in memory as a string. This provides an extremely easy-to-use method to split up our commands logically, and make it *very* flexible.

How Do We Use This?

Now that we have a method that we can use to flexibly call any possible command that is named in a string, we should create a single function that will handle any command, and from there call the associated function. In your CScriptParser class module, put this function:

Public Function ExecuteCommand(Command As String, Parameters() As String) As Integer ExecuteCommand = CallByName(Me, "ExecuteCmd" & Command, VbMethod, Parameters()) End Function

Next : Explanation