Upcoming Events
Workshop on Network and Systems Support for Games (NetGames 2009)
11/23 - 11/25 @ Paris, France

LOOP 2009
11/26 - 11/29  

EVA 2009
12/4 - 12/5 @ Buenos Aires, Argentina

ICIDS 2009 Interactive Storytelling
12/9 - 12/11 @ Guimarães, Portugal

More events...


Quick Stats
6334 people currently visiting GDNet.
2341 articles in the reference section.

Help us fight cancer!
Join SETI Team GDNet!



Link to us

Link to us

  Intel sponsors gamedev.net search:   

  Contents

 Introduction
 Explanation
 Command Blocks
 Improvements

 Printable version

 


  The Series

 Storing/Reading
 Doing Something
 Control Structures

 

Introduction

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