1. 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.

  2. 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.

  3. 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?

  4. 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
    
  5. That's because you define the function after you use it. You can't do that.

  6. 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.

  7. 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 variable foo, which is nil. 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):

    1. The global function init is created. There is a reference to the variable foo in the function, which since there is no other value foo in scope gets turned into a global variable lookup that will be done at runtime.
    2. The global function foo is created, wich prints a statement.
    3. The init function is called, which then looks up the global variable foo and executes the function referenced by that variable.

    Let me know if that makes sense!

  8. After rereading it a bunch, I think it finally makes sense. Thank you for taking the time to explain it.