An ExplanationThat 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 :
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.
|
||||||||||||||||||||