• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

C++ TFS 1.2 metatable bind problem

eduardbean

Member
Joined
Nov 26, 2010
Messages
129
Solutions
2
Reaction score
15
Good morning, I'm doing a new class called "Pokeball" that inherits the "Item" class.

But I'm having trouble binding the class to use it in LUA, I can not send the metatable to use the functions in Lua.

When i try to do this :

Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local pokeball = Pokeball(item.uid)
    print(pokeball)
    print("--")
    table.dump(getmetatable(pokeball))
    print("--")
    pokeball:setLevel(10)
    return true
end
I got this:

KyOIEDK4REycW5mju0tmKQ.png


print(pokeball) return userdata
but table.dump return empty
and setLevel is null

Here's the diff of what I changed on the server to try to make my new class, could someone point me to what I'm doing wrong or what's missing ??

[Diff] Pokeball System - Pastebin.com
 
Last edited:
Solution
I solved my problem changing this:

Code:
    // Pokeball
    registerClass("Pokeball", "Item", LuaScriptInterface::luaPokeballCreate);
    registerMetaMethod("Pokeball", "__eq", LuaScriptInterface::luaUserdataCompare);

    registerMetaMethod("Pokeball", "setPokemonId", LuaScriptInterface::luaPokeballSetPokemonId);
    registerMetaMethod("Pokeball", "setHealth", LuaScriptInterface::luaPokeballSetHealth);
    registerMetaMethod("Pokeball", "setMaxHealth", LuaScriptInterface::luaPokeballSetMaxHealth);
    registerMetaMethod("Pokeball", "setLevel", LuaScriptInterface::luaPokeballSetLevel);

To This:
Code:
    // Pokeball
    registerClass("Pokeball", "Item", LuaScriptInterface::luaPokeballCreate);
    registerMetaMethod("Pokeball"...
I solved my problem changing this:

Code:
    // Pokeball
    registerClass("Pokeball", "Item", LuaScriptInterface::luaPokeballCreate);
    registerMetaMethod("Pokeball", "__eq", LuaScriptInterface::luaUserdataCompare);

    registerMetaMethod("Pokeball", "setPokemonId", LuaScriptInterface::luaPokeballSetPokemonId);
    registerMetaMethod("Pokeball", "setHealth", LuaScriptInterface::luaPokeballSetHealth);
    registerMetaMethod("Pokeball", "setMaxHealth", LuaScriptInterface::luaPokeballSetMaxHealth);
    registerMetaMethod("Pokeball", "setLevel", LuaScriptInterface::luaPokeballSetLevel);

To This:
Code:
    // Pokeball
    registerClass("Pokeball", "Item", LuaScriptInterface::luaPokeballCreate);
    registerMetaMethod("Pokeball", "__eq", LuaScriptInterface::luaUserdataCompare);

    registerMethod("Pokeball", "setPokemonId", LuaScriptInterface::luaPokeballSetPokemonId);
    registerMethod("Pokeball", "setHealth", LuaScriptInterface::luaPokeballSetHealth);
    registerMethod("Pokeball", "setMaxHealth", LuaScriptInterface::luaPokeballSetMaxHealth);
    registerMethod("Pokeball", "setLevel", LuaScriptInterface::luaPokeballSetLevel);
 
Solution
Back
Top