I'm trying to write a extremely simple addon for WoW. I need to know if it is possible at all to delay a function for 30sec or a minute and then call a different function.
I tried to do a hack job with the following:
SLASH_PORTS1 = '/ports';
function pretalk()
if currentTime==currentTime+1 then
talk();
else
talkagain();
end
end
function talk()
SendChatMessage("selling PORTS 9g ea. 1g cheaper than the rest! PST." ,"CHANNEL" ,"COMMON" ,"2");
pretalk();
end
function SlashCmdList.PORTS()
currentTime = GetGameTime();
talk();
end
function talkagain()
pretalk();
end
But it doesn't work. It will send the first chat message and then won't manage to get the second one.
This can't be done the way you're looking at it.
GetGameTime()
is just informational only. You are not hooking any events at all in your code, except for the slash command. To be consistently polled by the game you would have to implement some kind of invisible window and hook the Paint event, and record the time each time, until you'd reached your condition. Or, better, find a 3rd party timer library that's done the work for you. (Try this one, for example.) Or better yet, extract the standard WoW interface code using the Addon Kit and examine the code for the inbuilt alarm clock and stopwatch function.However, I suspect even if you got this to work, you'd either gain the ire of players or GMs regarding your constant spamming of chat channels at a consistent pace.