[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Redefining a function
- From: Zhuang Zhao <zhuazhao@...>
- Date: Sun, 20 Jan 2008 20:17:00 -0800 (PST)
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.