Grayda
Member
- Joined
- May 20, 2010
- Messages
- 16
- Programming Experience
- 10+
For a bit of self education, I'm writing a game using XNA and using NLua for scripting. I've got three classes, clsBase (which defines the functions and subs all things in the game must be able to do), clsSprite (which is objects such as doors) and clsPlayer. The last two inherit from clsBase so that my codebase is rather nice and neat.
clsBase has a sub called move that does what it says on the tin, and clsPlayer has a sub of the same name that does things a little different (as it needs to work out stuff like orientation, object collision and such). clsBase (and therefore clsSprite and clsPlayer) has a variable called lua, which is a new NLua.Lua. They also have a sub, addLuaFunction(), which basically calls lua.RegisterFunction, and allows my Lua files to call real functions in my VB.NET app (such as a function to display a messagebox).
If the lua stuff is in it's own non-inheritable class, things work fine, but I can only have one Lua script loaded at a time, which isn't that great (?). But as soon as I add the Lua stuff to clsBase and run, I get this error:
And VB.NET 2013 Preview stops here:
The reason is fairly obvious to me -- I have a player and I have a door object -- both have a move sub, and VB.NET is not really sure which move() we're referring to, despite each move sub being in it's own class.
A Google search yielded nothing, but I did have some success by removing sub move() from all my derived classes, but that's not a good solution, as different things in the game move differently.
Any suggestions?
clsBase has a sub called move that does what it says on the tin, and clsPlayer has a sub of the same name that does things a little different (as it needs to work out stuff like orientation, object collision and such). clsBase (and therefore clsSprite and clsPlayer) has a variable called lua, which is a new NLua.Lua. They also have a sub, addLuaFunction(), which basically calls lua.RegisterFunction, and allows my Lua files to call real functions in my VB.NET app (such as a function to display a messagebox).
If the lua stuff is in it's own non-inheritable class, things work fine, but I can only have one Lua script loaded at a time, which isn't that great (?). But as soon as I add the Lua stuff to clsBase and run, I get this error:
An exception of type 'System.Reflection.AmbiguousMatchException' occurred in mscorlib.dll but was not handled in user code
Additional information: Ambiguous match found.
And VB.NET 2013 Preview stops here:
VB.NET:
Sub Main()
Dim player as New clsPlayer
Dim door as New clsObject
player.registerLuaFunction("move")
door.registerLuaFunction("move")
End Sub
' -------------------------------------------
' -------------------------------------------
' -------------------------------------------
' In clsBase:
Public Sub registerLuaFunction(functionName As String)
' Saves a bit of typing
lua.RegisterFunction(functionName, Me, Me.GetType().GetMethod(functionName)) ' <---- Stops right here with the ambiguous match error
End Sub
The reason is fairly obvious to me -- I have a player and I have a door object -- both have a move sub, and VB.NET is not really sure which move() we're referring to, despite each move sub being in it's own class.
A Google search yielded nothing, but I did have some success by removing sub move() from all my derived classes, but that's not a good solution, as different things in the game move differently.
Any suggestions?