Thread Tools Display Modes
05-07-14, 09:25 PM   #1
WhiteWolf87
A Deviate Faerie Dragon
 
WhiteWolf87's Avatar
AddOn Compiler - Click to view compilations
Join Date: Dec 2013
Posts: 16
Having trouble writing an addon

I am trying to set it up so that the addon checks to see if this character has installed this addon before. If the character did not install the addon then it brings up an installation frame. I know I'm probably missing something super easy, but I would appreciate the help... I've tried ready through World of Warcraft Programming, have spent 3 days reading forums and working on this... figured it was time to ask for help lol. I thought I would try looking at other addons to see how they did and used some of their code, but it isn't working right.

Note: Reworking the code, will get back to you.

Last edited by WhiteWolf87 : 05-11-14 at 08:45 PM. Reason: Reworking the code
  Reply With Quote
05-07-14, 10:07 PM   #2
Nimhfree
A Frostmaul Preserver
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 267
Bear in mind that it is late and I am really tired.

It appears that the signature for your OnEvent function should be (self, event, ...) instead of (event). What you are probably doing is comparing "ADDON_LOADED" to self instead of event.

Alos, in processing ADDON_LOADED you also want to check ... because the first parameter passed there will be the name of an addon. If it is not your addon name you should ignore it and not do any work. Basically your addon will be able to see other addons get loaded and it will be sent ADDON_LOADED for each. You are not guaranteed a specific order of those addon loads either.

So, you might want to change your code to:

function lf:OnEvent(self, event, ...)
if "ADDON_LOADED" == event then
if "LCI" == ... then
CheckNewChar()
end
end
end
  Reply With Quote
05-07-14, 11:01 PM   #3
WhiteWolf87
A Deviate Faerie Dragon
 
WhiteWolf87's Avatar
AddOn Compiler - Click to view compilations
Join Date: Dec 2013
Posts: 16
Originally Posted by Nimhfree View Post
Bear in mind that it is late and I am really tired.

It appears that the signature for your OnEvent function should be (self, event, ...) instead of (event). What you are probably doing is comparing "ADDON_LOADED" to self instead of event.

Alos, in processing ADDON_LOADED you also want to check ... because the first parameter passed there will be the name of an addon. If it is not your addon name you should ignore it and not do any work. Basically your addon will be able to see other addons get loaded and it will be sent ADDON_LOADED for each. You are not guaranteed a specific order of those addon loads either.

So, you might want to change your code to:

function lf:OnEvent(self, event, ...)
if "ADDON_LOADED" == event then
if "LCI" == ... then
CheckNewChar()
end
end
end
Thank you for responding. Gave it a try and nothing loaded when i tested it

Last edited by WhiteWolf87 : 05-07-14 at 11:32 PM.
  Reply With Quote
05-08-14, 01:16 AM   #4
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
Originally Posted by Nimhfree View Post
Bear in mind that it is late and I am really tired.

It appears that the signature for your OnEvent function should be (self, event, ...) instead of (event). What you are probably doing is comparing "ADDON_LOADED" to self instead of event.

Alos, in processing ADDON_LOADED you also want to check ... because the first parameter passed there will be the name of an addon. If it is not your addon name you should ignore it and not do any work. Basically your addon will be able to see other addons get loaded and it will be sent ADDON_LOADED for each. You are not guaranteed a specific order of those addon loads either.

So, you might want to change your code to:

function lf:OnEvent(self, event, ...)
if "ADDON_LOADED" == event then
if "LCI" == ... then
CheckNewChar()
end
end
end
Originally Posted by WhiteWolf87 View Post
Thank you for responding. Gave it a try and nothing loaded when i tested it
Not to good at lua but I do know that it needs to be
Code:
if event == "ADDON_LOADED"
not the other way around.
  Reply With Quote
05-08-14, 01:40 AM   #5
Clamsoda
A Frostmaul Preserver
Join Date: Nov 2011
Posts: 269
Not that it relates to the OP's issue, but that isn't true Cokedrivers. There is no syntax requirement for either string to come first. Keep in mind that event is just a string passed to the function (at least in this example). You can check for equality between the two in any order.
  Reply With Quote
05-08-14, 09:01 AM   #6
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
Originally Posted by Clamsoda View Post
Not that it relates to the OP's issue, but that isn't true Cokedrivers. There is no syntax requirement for either string to come first. Keep in mind that event is just a string passed to the function (at least in this example). You can check for equality between the two in any order.
Ok sorry about the reply, as I have stated before im no programmer.
  Reply With Quote
05-08-14, 09:52 AM   #7
ravagernl
Proceritate Corporis
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 1,176
Originally Posted by Clamsoda View Post
Not that it relates to the OP's issue, but that isn't true Cokedrivers. There is no syntax requirement for either string to come first. Keep in mind that event is just a string passed to the function (at least in this example). You can check for equality between the two in any order.
Setting the variable compare on the left side of the if statement does make more sense however as the corresponding pseudocode would be gramatically correct. It just reads better.

Code:
 
if event is the same as "ADDON_LOADED" then 
    dosomething()
end
  Reply With Quote
05-09-14, 05:45 AM   #8
WhiteWolf87
A Deviate Faerie Dragon
 
WhiteWolf87's Avatar
AddOn Compiler - Click to view compilations
Join Date: Dec 2013
Posts: 16
Either way, it isn't working.
  Reply With Quote
05-09-14, 06:47 AM   #9
WhiteWolf87
A Deviate Faerie Dragon
 
WhiteWolf87's Avatar
AddOn Compiler - Click to view compilations
Join Date: Dec 2013
Posts: 16
Update: From what I can tell it works until the code calls a global function.
  Reply With Quote
05-09-14, 09:06 AM   #10
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Are you getting an error?
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
05-09-14, 09:10 AM   #11
WhiteWolf87
A Deviate Faerie Dragon
 
WhiteWolf87's Avatar
AddOn Compiler - Click to view compilations
Join Date: Dec 2013
Posts: 16
No I am not, nothing shows up at all. It is like it doesn't want to run the first global function which bring up the setup frame I created.
  Reply With Quote
05-09-14, 10:10 AM   #12
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
Originally Posted by WhiteWolf87 View Post
No I am not, nothing shows up at all. It is like it doesn't want to run the first global function which bring up the setup frame I created.
As was suggested to me a while back, if you havent already install Bug Grabber. Wow errors don't always show.

Coke
  Reply With Quote
05-09-14, 10:13 AM   #13
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Make sure you enable Lua errors, but also your OnEvent signature was correct since colon syntax is used. You'll still want to make sure that it was your addon that loaded, though.
Code:
function lf:OnEvent(event, ...)
	if (event == "ADDON_LOADED") then
		if (... == "LCI") then -- needs to be same as your addon folder and ToC file name
			CheckNewChar()
		end
	end
end
print is your best friend in troubleshooting. Add it in functions that are meant to be executed to see where execution goes wrong and, if necessary, whether relevant variables have the expected values.
__________________
Grab your sword and fight the Horde!
  Reply With Quote
05-10-14, 09:52 AM   #14
Billtopia
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 110
so somewhere in your addon's lua file, like the first line you should have something like the following (outside of all functions)

lua Code:
  1. local AddonName, AddonTable = ...

this will give you the name that your addon is going to load as and a table that is global to all files loaded in your addon


then you just do something like the following.

lua Code:
  1. Frame:RegisterEvent("ADDON_LOADED")
  2. Frame:SetScript("OnEvent",function(self, event, ...)     local arg = ... -- used since arg will be indexable if a table and for more events
  3.      if event == "ADDON_LOADED" and arg  == AddonName then
  4.           --loading code here
  5.      end
  6.      -- other event code goes here
  7. end)

Last edited by Billtopia : 05-10-14 at 10:00 AM.
  Reply With Quote
05-10-14, 11:53 AM   #15
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
You know, this whole process would be a lot faster and more accurate if you posted your entire addon rather than one file and random snippets...
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
05-10-14, 12:59 PM   #16
Billtopia
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 110
I found your issue... the event handler you set up is wrong. it is supposed to be passed SELF, EVENT, ... you are, it seems, passing it nothing. no self, no event, and no ...

if you want to use any of the data from the event you must pass it to your function explicitly if you want to use the EVENT data you must pass SELF, and EVENT like in my example. You should also pass "..." as in my example so you can check to see if it is your addon being called or someone elses. Your addon can crash if it tries to init before wow inits it first, or force the setup to run 1- #addonLoaded + wow addons loading (OK not quite that many times but you can/will have problems)
  Reply With Quote
05-11-14, 12:35 AM   #17
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Billtopia View Post
I found your issue... the event handler you set up is wrong. it is supposed to be passed SELF, EVENT, ... you are, it seems, passing it nothing. no self, no event, and no ...
You're at least the second person to post that, and like the others before you, you're wrong. He is passing the self in -- that's what method notation (colon) does.

However, I've been avoiding this thread because OP's code is obviously borrowing from some old and really badly written examples that I'd really rather swallow live spiders than work with, but since OP didn't post the entire addon and the file they posted makes multiple references to functions and other things that are (I assume) in other files, I can't just rewrite it for them.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
05-11-14, 06:54 AM   #18
Billtopia
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 110
that is not the self I meant... I know that he is specifically passing his frame by calling his function via a colon, what I meant is that when the "ADDON_LOADED" event fires it gives you 3 arguments, self, event, addon_name


with the way he is calling his handler would his function prototype/declaration not need an extra variable like the following:


function(frame, self, event, addon_name)
  Reply With Quote
05-11-14, 11:29 AM   #19
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Lua Code:
  1. function lf:OnEvent(event)
  2.   if (event == "ADDON_LOADED") then
  3.     CheckNewChar()
  4.   end
  5. end
  6. lf:SetScript("OnEvent", lf.OnEvent)

This is perfectly fine. The function lf:OnEvent makes OnEvent a method of the frame lf. When you assign lf.OnEvent to the event handler, self and event get passed through automatically. Using lf:OnEvent means that lf *is* self, so only event is needed in the parentheses.

Now.... He does still need to check if it was his addon that loaded.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
05-11-14, 01:33 PM   #20
Billtopia
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 110
I see what you are saying there... that when defining a method it adds the 'self' variable in before the function variables... I was thinking that it did it by setting the first variable to self

I guess he will still need to add a variable to hold the addonName that is loading so he can init his setup when it is his turn
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Having trouble writing an addon

Thread Tools
Display Modes

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