View Full Version : Why Doesn't This Code Work
Tunga
20-10-2006, 12:46 PM
I'm trying to do something when eveer CLOSE_WORLD_MAP fires, but my code doesn't work. I have a feel this event doesn't actually ever fire, but even when I replace the event with one that I know works, for example MINIMAP_ PING, this still won't work:
function Simple_OnLoad()
this:RegisterEvent("CLOSE_WORLD_MAP");
this:RegisterEvent("MINIMAP_PING");
SLASH_SIMPLE1 = "/simple";
SlashCmdList["SIMPLE"] = function()
Simple_OnEvent();
end
end
function Simple_OnEvent(event)
SendChatMessage("World Map Closed!", "SAY");
end
The slash command works so I know my OnEvent function is working. Do I need to tell it somewhere to use this function whenever a registered event fires? Any ideas?
freeri
20-10-2006, 03:42 PM
You need a xml file that contains a frame that captures and sends registred events to your lua file.
<Frame name="YourFrameNavn" hidden="true">
<Scripts>
<OnEvent>
Simple_OnEvent(event);
</OnEvent>
</Scripts>
</Frame>
And then you have to check if event is CLOSE_WORLD_MAP in your event function.
Tunga
20-10-2006, 08:53 PM
Surely I don't need to check the event since I'm only doing one thing (and I'll only have one event registered)? I was missing the other part in my XML though, thanks. I'll see if it works now.
Tunga
20-10-2006, 08:58 PM
The event doesn't fire, it works with a number of other events. Good job Blizzard.
freeri
21-10-2006, 06:07 PM
Don't blame Blizzard. It sure works, but you are probably doing it wrong.
If you post your whole code it will be easyer to help.
Tunga
22-10-2006, 11:34 AM
That's the entire mod except for the XML which has the OnEvent bit above and also basically the same thing for OnLoad.
Since the code works perfectly for any other event I give it, like MINIMAP_PING, I don't really see how it could be my code. Either that event doesn't exist or it doesn't fire, either way the result is the same. I can't actually find any existing mod that uses it.
freeri
22-10-2006, 01:48 PM
Okay. If you don't even want to try, it's fine for me.
Tunga
22-10-2006, 09:13 PM
There is nothing to try, if the only line of code I change is the event name and suddenly it doesn't work then the error is clearly that the event doesn't exist (or work). I don't have the XML any more because I deleted it, but like I say it worked anyway.
I got some decent replies in the other thread so it's fine, thanks anyway.
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.