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:

  Contents

 Introduction
 Explanation
 Command Blocks
 Improvements

 Printable version

 


  The Series

 Storing/Reading
 Doing Something
 Control Structures

 

An Explanation

That ExecuteCommand function can be called whenever you want to parse ANY of your scripting commands. It is a 'generic' function that will 'wrap' around each of the other functions for the individual scripting commands.

Speaking of the individual scripting commands' functions, how do we make them? Here is a very simple example :

Public Function ExecuteCmdFoo(a() As String) As Integer Debug.Print a(0) Foo = 1 End Function

Basically, you create a function for each of your possible scripting commands, named the same as the command but prefixed with 'ExecuteCmd'. In the above example, the command that would call this function would be 'Foo'. By returning a value of 1, the call to ExecuteCommand would also return a value of 1. The return value gets passed down the chain, you can return values from your 'wrapped' command functions.

The only 'sad' part about using CallByName is that the functions *must* be Public, not Private. But, having those command functions public can actually be a good thing; You can use them from within your code as well. For example, say you had a tile-based game with multiple maps, and you knew that every single map would be linked in a uniform fashion to other maps on the edge tiles. You could have a scripting command 'TeleportToMap' that could not only be used in your scripts for events such as walking onto a door tile to bring you inside a building, but you could have your player movement code check all the time if the player moves off the map, and call the ExecuteCmdTeleportToMap function without the 'wrapper' ExecuteCommand function to move the player to the adjacent map. Therefore, it's not so bad to have the functions public anyways.


Next : Command Blocks