After our work from the previous post, we have a skeleton of the functionality provided by the Lua command we're working on. However, working from assembly isn't always the best approach. For EMI, we already have a whole lot of help from the excellent work done by the developers who previously worked on Grim Fandango, EMI and Myst3 support in ResidualVM! In this project, they have provided us with code and tools to inspect the scripts that are being run in the game. Let's inspect a script that called the function stub we're working on.
First, let's take a look at the game scripts. In EMI, the game scripts can be found in the file local.m4b. This file is actually a bundle of files, which can be extracted using the tool unlab, found in the residualvm-utils repository. Once you've built this utility, let's unpack it so we can get at the Lua scripts that make up the game. In the directory with the EMI data files:
- mkdir local
- cd local
- unlab ../local.m4b
- mkdir scripts
- for i in *.lua; do delua $i > scripts/$i; done
- cd scripts
- grep SetActorLocalAlpha *.lua
Before we go back to SetActorLocalAlpha, let's examine the set_vertex_alpha_mode Lua function more closely. As you can see in the code listing above, there are a bunch of unnamed variables. Let's figure out what they mean so that we can better identify the arguments to SetActorLocalAlpha. Let's start with the function arguments.
In Lua, a method function can be called in two different ways, with a period between the class and the method or a colon. These methods differ in that the second transparently passes a reference to the object as the first argument. In most applications, we name this argument "self". In wed.lua, we see that the set_vertex_alpha_mode method is called using the colon operator. Because of this, we know that the first argument is really the "self" variable. Once we have identified a variable like this, we'll update the rest of the function to reflect this new knowledge. We'll continue this process, using cues from the calling function and the contents of the function to name the rest of the arguments and the local variables
With all of this additional information, we can now continue filling in the details for the SetActorLocalAlpha function.
No comments:
Post a Comment