Lua script not recognizing self.id

817 views Asked by At

I'm revising an existing program to implement a new toolbar. The program uses Lua scripts to handle the display and processing of Flash animations and commands. I can call up the Flash animation window, but the line that adds a command listener fails.

HUD.AddFSCommandListener(self.file_SWF, self.id)

The error is: "Wrong parameter type. Function HUD.AddFSCommandListener(movie, entityId) expect parameter 2 of type Pointer (Provided type Null)".

I have been over, under and around through the system, and I cannot figure out what I'm doing wrong, although I suspect there is some kind of registration step that I'm not doing correctly. The game I'm working on uses CryEngine, and I see there aren't a lot of people asking questions about it. However, if this error has some kind of analog in another system, then perhaps that might spark my mind as to what I need to do.

Thanks.

1

There are 1 answers

0
Charles Randall On

Your issue is likely that you need to actually do

HUD:AddFSCommandListener(self.file_SWF, self.id)

The issue isn't that it's not recognizing self.id, but that when you call using dot notation, the first parameter you pass becomes the function's 'self' parameter, if that function was meant to be a table function. So the second paramater it's looking for is actually nil.

The colon function notation is syntactic sugar for implicitly passing in a self variable, where self becomes the table (in this case HUD). Most lua interfaces will thus start counting from the second parameter. So the second one it's talking about is actually the third.

Example:

HUD = {}

function HUD:AddFSCommandListener(file, id)

end

is actually equivalent to this:

HUD = {}

HUD.AddFSCommandListener = function( self, file, id )

end

And so when you call with a dot instead of a colon, you shove your file_swf into what it most likely expects as a self parameter.