Thread Tools Display Modes
04/07/14, 03:22 PM   #1
skyraker
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 154
What's wrong with this?

Lua Code:
  1. function ABT.initBookTrack(code, addOnName)
  2.     if (addOnName == "BookTracker") then
  3.         SLASH_COMMANDS["/mybooks"] = ABT.showBookWindow
  4.     end
  5. end
  6.  
  7. EVENT_MANAGER:RegisterForEvent("bookTrack", EVENT_ADD_ON_LOADED , ABT.initBookTrack)

The slash command is not being added. Yes, ABT.initBookTrack is defined. Yes, BookTracker is the title of the addon in my txt file.
  Reply With Quote
04/07/14, 03:29 PM   #2
ins
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 76
Try putting it (SLASH_COMMANDS["/mybooks"] = ABT.showBookWindow) outside the function.
  Reply With Quote
04/07/14, 03:55 PM   #3
Xrystal
caritas omnia vincit
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 369
Is ABT.showBookWindow defined as a function. The slash command line tries to run a function that processes the command line for options and allows you to test for them.

The WIKI page has a section on how to make slash commands work. I added some extra stuff to it for multiple options.
  Reply With Quote
04/07/14, 05:16 PM   #4
skyraker
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 154
Originally Posted by ins View Post
Try putting it (SLASH_COMMANDS["/mybooks"] = ABT.showBookWindow) outside the function.
Originally Posted by Xrystal View Post
Is ABT.showBookWindow defined as a function. The slash command line tries to run a function that processes the command line for options and allows you to test for them.

The WIKI page has a section on how to make slash commands work. I added some extra stuff to it for multiple options.
Putting it outside functions works, but it defeats the purpose of putting it in after the addon is verified.

Yes, ABT.showBookWindow is defined.

I think it has to do with the Event call, because nothing I put in the conditional seems to work.
  Reply With Quote
04/07/14, 05:33 PM   #5
Xrystal
caritas omnia vincit
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 369
Hmm, try a regular function name rather than one inside ABT table. I always used to have problems calling functions within a table within a function call for some reason. Other than that difference your code is almost identical to my own. The only other difference is I use the first parameter in the event registration as the name of the addon but I think it only needs to be unique rather than a specific name.

Try this variation and see if it works. If it does then hopefully one of the Lua experts can explain why your way doesn't work, cos I have no idea why.

Lua Code:
  1. local function AddonLoaded(code, addOnName)
  2.     if (addOnName == "BookTracker") then
  3.         SLASH_COMMANDS["/mybooks"] = ABT.showBookWindow
  4.     end
  5. end
  6.  
  7. EVENT_MANAGER:RegisterForEvent("bookTrack", EVENT_ADD_ON_LOADED , AddonLoaded)
  Reply With Quote
04/07/14, 05:38 PM   #6
skyraker
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 154
No, sadly. Making it a function outside ABT didn't work.
  Reply With Quote
04/07/14, 06:14 PM   #7
Xrystal
caritas omnia vincit
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 369
Okay, let's find out exactly what is happening.

1. It isn't kicking up an error ?
2. You are typing the slash command EXACTLY as you have typed it in your addon, in lower case ?
3. What exactly are you typing ?
4. What does your slash command function do when you do not type anything after the slash command itself ?
5. It is activating the ABT.initBookTrack function and allocating the function to the slash command table ?

Step 5 is a bit hard to do but you could go that one step further and put a debug statement into the slash command function itself to see if it gets activated, even if it doesn't do what you expect later.

I personally cannot see any reason why it won't work for you despite the slight differences to my own code. I can only assume something else is causing a problem somewhere that is making the slash command not work.

Can you put up what your slash command function looks like. It would give us an idea if something is causing a problem at that stage.
  Reply With Quote
04/07/14, 06:47 PM   #8
skyraker
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 154
Originally Posted by Xrystal View Post
Okay, let's find out exactly what is happening.

1. It isn't kicking up an error ?
2. You are typing the slash command EXACTLY as you have typed it in your addon, in lower case ?
3. What exactly are you typing ?
4. What does your slash command function do when you do not type anything after the slash command itself ?
5. It is activating the ABT.initBookTrack function and allocating the function to the slash command table ?

Step 5 is a bit hard to do but you could go that one step further and put a debug statement into the slash command function itself to see if it gets activated, even if it doesn't do what you expect later.

I personally cannot see any reason why it won't work for you despite the slight differences to my own code. I can only assume something else is causing a problem somewhere that is making the slash command not work.

Can you put up what your slash command function looks like. It would give us an idea if something is causing a problem at that stage.
#5 is where I think the problem is. The slash command is not even showing up in zgoo, which to me means it isn't registering. Since it did show up when I moved the slash command declaration outside the initialization function, I'm even more convinced that is where the problem is. I am going to try moving it outside the conditional statement only, and if it still doesn't register then I would say it is something with the event registration.
  Reply With Quote
04/07/14, 06:50 PM   #9
skyraker
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 154
Yeah, when it is outside the conditional, it gets registered. So something is wrong with if (addOnName == "BookTracker") then
  Reply With Quote
04/07/14, 07:38 PM   #10
Xrystal
caritas omnia vincit
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 369
Hmm, and it is definitely called BookTracker ? The folder name and txt file both have that as a name ? They both have to be called it to be treated as such. Is it showing in the addon list with it inside or outside the condition ?
  Reply With Quote
04/07/14, 08:09 PM   #11
skyraker
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 154
Originally Posted by Xrystal View Post
Hmm, and it is definitely called BookTracker ? The folder name and txt file both have that as a name ? They both have to be called it to be treated as such. Is it showing in the addon list with it inside or outside the condition ?
Appears that the file name has to match the addon name (including capitalization) for it to work. My file names were all lower case even though the folder had matching capitalization.
  Reply With Quote
04/07/14, 08:36 PM   #12
ins
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 76
Originally Posted by skyraker View Post
Appears that the file name has to match the addon name (including capitalization) for it to work. My file names were all lower case even though the folder had matching capitalization.
Sticky.

And.

wth?
  Reply With Quote
04/07/14, 09:07 PM   #13
Xrystal
caritas omnia vincit
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 369
Oh sheesh, I should have realised that would be the case seeing as the addon's themselves are case specific. Data and data are not the same if used as variables or keys in tables.

Strange how the obvious is not at the top of your mind. Glad you got it figured out though.
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » What's wrong with this?


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