-
Posted by Drunk Cadaver on Sat, 17 Apr 2010 23:52:16
I'm trying to add an "auto release in WG and BGs" option to my mod. I have looked up mods with similar options and tried to come up with something but it's not working. I tested the mod in WG by dismounting and falling to my death, but after 40 gold worth of repairs testing the code, I thought I would just ask here. Here is the code I have so far.
local corpse = CreateFrame("frame") corpse:RegisterEvent("PLAYER_DEAD") corpse:SetScript("OnEvent", wgh_repop) local function wgh_repop() local mapname = (select(1,GetMapInfo())) if (mapname == "LakeWintergrasp" or mapname == "AlteracValley" or mapname == "StrandoftheAncients" or mapname == "IsleofConquest" or mapname == "WarsongGulch" or mapname == "ArathiBasin" or mapname == "NetherstormArena" ) then RepopMe() end end
Any help would be greatly appreciated.
-
Posted by jnwhiteh on Sun, 18 Apr 2010 05:34:48
No idea. Have you added debug messages to ensure your code is being called? Where precisely is it failing? This is the same method that SSPVP uses to accomplish the same task, as far as I can see.
-
Posted by Drunk Cadaver on Sun, 18 Apr 2010 23:54:21
I wasn't expecting to get a reply so fast since you had your surgery. I hope that went well for you and you have a quick recovery.
I've tested the mod in Wintergrasp by dismounting and dropping to me death (stripped naked this time to avoid a repair bill... /sigh). I've died in an actual battle in Wintergrasp as well as in Eye of the Storm. It's not released me once. How exactly do I put debug messages in it? Do you mean something like print("releasing") or do I use the Debug API?
-
Posted by Drunk Cadaver on Mon, 19 Apr 2010 00:54:24
I changed the code to print a message whenever the function was called. It's outside the "mapname" part so it should just print it whether I'm in a BG/WG or not, but it didn't print anything.
local corpse = CreateFrame("frame") corpse:RegisterEvent("PLAYER_DEAD") corpse:SetScript("OnEvent", wgh_repop) local function wgh_repop() print("Releasing to GY") local mapname = (select(1,GetMapInfo())) if (mapname == "LakeWintergrasp" or mapname == "AlteracValley" or mapname == "StrandoftheAncients" or mapname == "IsleofConquest" or mapname == "WarsongGulch" or mapname == "ArathiBasin" or mapname == "NetherstormArena" ) then RepopMe() end end
-
Posted by jnwhiteh on Mon, 19 Apr 2010 10:06:38
That's because you define the function after you use it. You can't do that.
-
Posted by Drunk Cadaver on Mon, 19 Apr 2010 14:12:28
I have another really simple mod I wrote that does something when an event is registered. It uses "frame:SetScript("OnEvent", function(self, event, ...)" and the function follows. I think this is where I was confused. I think I actually understand the "function(self, event, ...)" part a little better now from my other mod.
That corrected the problem though. Thank you for the help.
-
Posted by jnwhiteh on Mon, 19 Apr 2010 16:41:20
Its te fact that it was local that is the issue. A function can be defined after its used if its global, but not local. It's a bit confusing, but consider the following examples (where the init function is something that might be called on ADDON_LOADED or something similar).
> function init() foo() end; local function foo() print("Calling foo()") end; init() stdin:1: attempt to call global 'foo' (a nil value) stack traceback: stdin:1: in function 'init' stdin:1: in main chunk [C]: ?
This fails because the variable
foo
in init is the global variablefoo
, which isnil
. Alternatively:> function init() foo() end; function foo() print("Calling foo()") end; init() Calling foo()
This works because it's processed in the following way (roughly):
- The global function init is created. There is a reference to the variable
foo
in the function, which since there is no other valuefoo
in scope gets turned into a global variable lookup that will be done at runtime. - The global function foo is created, wich prints a statement.
- The
init
function is called, which then looks up the global variablefoo
and executes the function referenced by that variable.
Let me know if that makes sense!
- The global function init is created. There is a reference to the variable
-
Posted by Drunk Cadaver on Mon, 19 Apr 2010 18:40:12
After rereading it a bunch, I think it finally makes sense. Thank you for taking the time to explain it.