home |
the black hole's front page. all the latest vb rpg development and vbgaming news, as well as this week's feature rpg project! |
rpg projects
|
vb rpg projects under development by members of the bhC. show them your
support, and check out their games! |
message board |
a forum to interact with your fellow vb rpg programmers. you do *not* have
to be a bhC member to post! |
contact |
you want to contact the guy behind the black hole? here's where to
do it! |
|
|
 |
|
<< Back to Category List
Simple Game Scripting Part 2: Making Your Scripts DO Something - page 2 |
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
|