Thread Tools Display Modes
04-19-10, 10:59 AM   #1
Jack332
A Murloc Raider
Join Date: Apr 2010
Posts: 9
Unhappy beginner: problem with PLAYER_LEVEL_UP event...

hi there!
i have a question and hope to get some help here. i´m new to lua, xml and addons and i´m playing around with very basic things atm.

first lesson i did was a simple ding msg on level up which looks like:
Code:
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\FrameXML\UI.xsd">
<Script file="LevelUp.lua"/> 
	<Frame name="LevelUpFrame" hidden="true">
		<Scripts>
			<OnLoad>
				LevelUp_OnLoad();
			</OnLoad>
			<OnEvent>
				LevelUp_OnEvent(event);
			</OnEvent>
		</Scripts>
	</Frame>
</Ui>
Code:
function LevelUp_OnLoad()
	this:RegisterEvent("PLAYER_LEVEL_UP");
	end

function LevelUp_OnEvent(event)
        if (event == "PLAYER_LEVEL_UP") then
		level = UnitLevel("player") +1;
	SendChatMessage(" level "..level.."","SAY");
        end
end
this one is working fine!
the problem is:
i want to add a small function to an existing addon on PLAYER_LEVEL_UP event and i can´t get it to work! it seems like the function is not executed on level up, nothing happens. after that, when i type /script ReloadUI() at the console, then the function is suddenly executed. when i use MERCHANT_SHOW for example instead of PLAYER_LEVEL_UP then the function is executed when the merchant window opens without reloading ui. the principe is the same as the code above.
this one works:
Code:
	function LevelUp_OnLoad()
	this:RegisterEvent("MERCHANT_SHOW");
	end

	function LevelUp_OnEvent(event)
			if (event == "MERCHANT_SHOW") then
			local level = UnitLevel("player");
			if level >= 1 then
	LoadProfile();
	end
	end
	end
but the function must be executed on PLAYER_LEVEL_UP event.
i dont get it, from my point of view this must work!
what is it i´m missing...

btw: can i use ReloadUI() from the script somehow? i tried but it does not work.

regards

Last edited by Jack332 : 04-19-10 at 11:15 AM.
  Reply With Quote
04-19-10, 05:05 PM   #2
harrellj
A Flamescale Wyrmkin
Join Date: Jul 2009
Posts: 132
That if level >=1 bit? Should be in ().

So, it'd be:
Code:
	function LevelUp_OnLoad()
	  this:RegisterEvent("MERCHANT_SHOW");
	end

	function LevelUp_OnEvent(event)
	  if (event == "MERCHANT_SHOW") then
	    local level = UnitLevel("player");
	    if (level >= 1) then
               LoadProfile();
            end
	  end
	end
I had to clean up the whitespacing to make it easier to read for myself too :P
  Reply With Quote
04-19-10, 05:30 PM   #3
cloudwolf
A Black Drake
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 87
Harrellj you do not need to cover an if statement in parenthesis. Also jack might i suggest removing xml all together you can do basically allt he same functions with lua. it means there's 1 less file to deal with and 1 less dependency. And i'm sorry that i can't seem to find the error in your code or have an answer for you jack.
  Reply With Quote
04-19-10, 05:36 PM   #4
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
Originally Posted by harrellj View Post
That if level >=1 bit? Should be in ().
The () are actually optional in that situation.

To the OP, could you post the actual code that you're trying to get to work, in the context of the addon that you're trying to modify?
  Reply With Quote
04-19-10, 07:26 PM   #5
Jack332
A Murloc Raider
Join Date: Apr 2010
Posts: 9
@harrellj: as i wrote, that code works so it should be alright. the same code with PLAYER_LEVEL_UP only works when i do a /script ReloadUI() after it.

@cloudwolf: i first did this in lua only and it had the same issue. the ding! on level up works but the function i want to call does only when i reloadui. thats why i tried it with the xml file.

@Akryn: its too long to post it here. i would like to add a function on event to the addon macaroon. according to its license, im allowed to do that if i understood right. i would like to build in an autoload on levelup function. i play wow often with different chars but im lazy when it comes to making new makros an setup my actionbars. with macaroon you can save sets of macros,bars,keybindings,...you can even exchange whole sets with your friends, making life a lot easier for me. so the idea was: wouldnt it be cool if these sets would get automatically loaded an a certain level? yes, i think so! i thought this would be easy as i did a similiar thing with an other addon and it works well!
apparently it´s not as easy as i thought...

thanks for your answers so far! i´ll try again tomorrow.

regards
  Reply With Quote
04-19-10, 09:55 PM   #6
Waverian
A Chromatic Dragonspawn
AddOn Author - Click to view addons
Join Date: Dec 2006
Posts: 188
I haven't really looked at your code but I can't duplicate this problem.

Code:
local f = CreateFrame'Frame'
f:RegisterEvent('PLAYER_LEVEL_UP')
f:SetScript('OnEvent', function(_, _, level)
	print('Level: '..level)
end)
Fires fine on first login with no reload.
  Reply With Quote
04-20-10, 12:17 AM   #7
nightcracker
A Molten Giant
 
nightcracker's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 716
Originally Posted by harrellj View Post
That if level >=1 bit? Should be in ().

So, it'd be:
Code:
	function LevelUp_OnLoad()
	  this:RegisterEvent("MERCHANT_SHOW");
	end

	function LevelUp_OnEvent(event)
	  if (event == "MERCHANT_SHOW") then
	    local level = UnitLevel("player");
	    if (level >= 1) then
               LoadProfile();
            end
	  end
	end
I had to clean up the whitespacing to make it easier to read for myself too :P
This my dear, is complete bull****.
__________________
Three things are certain,
Death, taxes and site not found,
You, victim of one.
  Reply With Quote
04-20-10, 12:32 AM   #8
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
Originally Posted by Jack332 View Post
@harrellj: as i wrote, that code works so it should be alright. the same code with PLAYER_LEVEL_UP only works when i do a /script ReloadUI() after it.
Is the function in your code placed in front of your call ?
The order matters (sometimes).

Code:
local function lala()
...
end

local function otherlala()
 ...
 lala()
end
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
04-20-10, 05:02 AM   #9
Jack332
A Murloc Raider
Join Date: Apr 2010
Posts: 9
@ Waverian: yes, of course. that´s not the problem, the levelup message is shown correctly but i want to call the function LoadProfile() too and it does not work.

@Rilgamon: i tried to put the code infront and behind the call now with the same result. nothing changes until i reloadui.

i tried many different things but it all ends up the same.

could this be the problem?
from the official macaroon thread:

"Macaroon is distributed as two addons, Macaroon and MacaroonProfiles. MacaroonProfiles is only needed is you decide to save profiles of Macaroon setups. MacaroonProfiles does not even load unless you go to the Profiles configuration menu or load a profile."

i put my call in the main part but the function i want to call is in the profile part. putting the call into the profile part does not work at all because it only loads when you access the menu...

the last thing i tried was
Code:
local f = CreateFrame'Frame'
f:RegisterEvent('PLAYER_LEVEL_UP')
f:SetScript("OnEvent", function (event)
 	if (not IsAddOnLoaded("MacaroonProfiles")) then
		LoadAddOn("MacaroonProfiles")
	end
for k,v in pairs(Macaroon.SavedDataLoad) do
data = copyTable(MacaroonProfiles["mysetup1"][k])
v(data, true)
end

for k,v in pairs(Macaroon.SavedDataUpdate) do
v()
end
end)
but with same result...

and again, it works when using MERCHANT_SHOW instead of PLAYER_LEVEL_UP


any bright idea on this?

i´ll try some more later...

regards
  Reply With Quote
04-20-10, 05:53 AM   #10
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,360
PHP Code:
local dinger CreateFrame("Frame")
dinger:SetScript("OnEvent", function(self,event,...)
    
self[event](self,event,...)
end)
dinger:RegisterEvent("PLAYER_LEVEL_UP")
function 
dinger.PLAYER_LEVEL_UP(self,event,...)
    
local newlevel = ...
    
local togo MAX_PLAYER_LEVEL newlevel
    local msg 
togo and string.format("%d |4level:levels; to go!",togo) or "Congratulations! Leveling done."
    
DEFAULT_CHAT_FRAME:AddMessage(msg)
end 
  Reply With Quote
04-20-10, 09:00 AM   #11
Jack332
A Murloc Raider
Join Date: Apr 2010
Posts: 9
this one works too but i dont want a dinger, it was just an example.
so this is what the code looks like now:
Code:
local f = CreateFrame("Frame")
f:SetScript("OnEvent", function(self,event,...)
    self[event](self,event,...)
end)
f:RegisterEvent("PLAYER_LEVEL_UP")


function f.PLAYER_LEVEL_UP(self,event,...)

 	if (not IsAddOnLoaded("MacaroonProfiles")) then
		LoadAddOn("MacaroonProfiles")
	end
for k,v in pairs(Macaroon.SavedDataLoad) do
data = copyTable(MacaroonProfiles["mysetup1"][k])
v(data, true)
end

for k,v in pairs(Macaroon.SavedDataUpdate) do
v()
end
end
same behaviour... after reloading ui it it works and so on...
its really annoying!

it works on other events or if i bind the function to a button. i dont understand that...

is there any way to reloadui from lua script?

Last edited by Jack332 : 04-20-10 at 09:15 AM.
  Reply With Quote
04-20-10, 11:49 AM   #12
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
You can use ReloadUI(), but I believe the execution path must originate with a hardware event (keyboard/mouse). If you call it in an update/event handler it will just fail.
  Reply With Quote
04-20-10, 12:08 PM   #13
Jack332
A Murloc Raider
Join Date: Apr 2010
Posts: 9
i already tried reloadui from script and it didnt work. now i understand why.

i dont give up, i´ll try some more tomorrow.
  Reply With Quote
04-21-10, 06:18 AM   #14
Jack332
A Murloc Raider
Join Date: Apr 2010
Posts: 9
i tried again to get it right for hours, without success.
the code itself works, it must have something to do with macaroon, the way it loads profiles.
well, i dont think i´ll get this working, no matter how much time i spend on it.
still hope somebody takes a look at the code of macaroon and points me to the right direction.

btw: is there any other addon that offers similiar functions like macaroon? i tried some other addons before,simple action sets for example, but they were always limited to the 18 standard macro slots per toon, thats not enough.
  Reply With Quote
04-21-10, 01:16 PM   #15
harrellj
A Flamescale Wyrmkin
Join Date: Jul 2009
Posts: 132
Originally Posted by nightcracker View Post
This my dear, is complete bull****.
So I'm seeing from everyone else. Oh well, I thought I've run into languages where using that sort of syntax would screw things up, so wanted to make sure that wasn't the issue.
  Reply With Quote
04-25-10, 06:21 AM   #16
Jack332
A Murloc Raider
Join Date: Apr 2010
Posts: 9
just wanted to tell you that i believe i found the problem.
i think this does not work on player level up because macaroon blocks switching profiles during combat. when you level up you are still in combat, so this cant work. for some strange reason i dont get it to work anymore as i did with merchant show. maybe try again tomorrow...
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » beginner: problem with PLAYER_LEVEL_UP event...


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off