lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi everyone,

I'm currently coding a modification for a game using lua, and I want to redefine a function. The function is called OnTick, and is called every second. Here's the original ,

function PowerStruggle:OnTick()
    System.LogAlways("++++++++++++OnTick++++++++++");
    if (self:GetState()~="PostGame") then
        self:UpdateReviveQueue();
    end
   
    TeamInstantAction.OnTick(self);
end

And here's my hook creation function,

function hookFunction()
    local oldTick = PowerStruggle.OnTick;
    LogAlways("oldfunc:"..tostring(PowerStruggle.OnTick));
    PowerStruggle._OnTick_ = function()
        LogAlways("*****************************OnTick Hooked!!!****************************");
        - oldTick(obj);
        return;
    end
    LogAlways("newfunc"..tostring(PowerStruggle.OnTick));
end

This hook function, however, does not work. It just prints the original
++++++++++++OnTick++++++++++ rather than both. Also, the LogAlways statement shows the memory address for the function is changing. Anyone have any idea why it's failing?


Thanks,
James


If You ahve any questions, please call me at 301-610-9966    zhuazhao@yahoo.com


Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now.