Reply
Thread Tools Display Modes
Unread 11-16-12, 01:01 AM   #1
gmarco
Premium Member
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 97
Compaions API broken ?

Hi,

I am trying to make an addon about companions / pets but I always get an error when I use the function:

Lua Code:
  1. CallCompanion("CRITTER",index);

where index <= GetNumCompanions("CRITTER")

The error is something like in English "You don't have any pets" (in italian is "Non hai un famiglio").

But a simple for loop print the name of all my pets:

Lua Code:
  1. for index=1,GetNumCompanions("CRITTER") do
  2.    local _,name=GetCompanionInfo("CRITTER",index);
  3.    print(name:lower())
  4. end

Also the other summon function

Lua Code:
  1. SummonRandomCritter()

gives to me the same error.

Probably the new pet combat system broken the api.

Am I looking in a wrong place for outdated documentation ? (http://wowprogramming.com and http://www.wowwiki.com/API_CallCompanion)

Should I use an external library like LibPetJournal ?

Or simply I missing something ? :-)

Thanks in advance for any help.
gmarco is offline   Reply With Quote
Unread 11-16-12, 01:41 AM   #2
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,051
The code you posted will only work for old-style (pre 5.x) pets. You'll need to use the C_PetJournal functions for them now to access both old and new-style. Take a look at some of the newer Pet-centric AddOns (such as Pet Theory) for some code examples.

I'd use WoWPedia over WoWWiki, as it's much better maintained.
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of Revelation, Spamalyzer, TravelAgent, Volumizer, and many other AddOns.
Torhal is offline   Reply With Quote
Unread 11-16-12, 02:49 AM   #3
Phanx
A Pyroguard Emberseer
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 4,267
To clarify, the old API functions will still work for any companion pets your character had before Patch 5.0.4, but they will not work for any companion pets that were originally learned by one of your other characters before Patch 5.0.4 (even though they are now "known" by all of your characters), and they will not work for any companion pets learned by any character after the release of Patch 5.0.4.
__________________
Author/maintainer of Grid, PhanxChat, ShieldsUp, and many more.
Troubleshoot an addonTurn any code into an addonMore addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please don’t PM me about addon bugs or code questions. Post a comment or forum thread instead!
Phanx is offline   Reply With Quote
Unread 11-16-12, 02:32 PM   #4
gmarco
Premium Member
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 97
Ok I made a little addon to summon a random companion fom the full collection or from a custom category is defined.

Like mine first addon you can define some samples category like:

Lua Code:
  1. pets = {
  2.    
  3.    funny = {
  4.         "Willy",
  5.         "Toothy",
  6.    },
  7.    
  8.    rare = {
  9.         "Senegal",
  10.         "Pengu",
  11.         "Azure Whelphling",
  12.         "Baby Blizzard Bear",
  13.    },
  14.    
  15.     cat = {
  16.         "Cornish Rex Cat",
  17.         "Bombay Cat",
  18.         "Orange Tabby Cat",
  19.     },
  20.    
  21.     favorite = {
  22.         "Ravasaur Hatchling",
  23.         "Razzashi Hatchling",
  24.         "Proto-Drake Whelp",
  25.     },
  26.    
  27.    -- add your custom categories here
  28. }

and then use the magic way "Phanx" macro :-) to use the program:

/gimb [btn:2] rare; [btn:3] funny;

There is a little "help" switch to show the available options.

I post it here so I hope that someone can give it a try to check it before I commit to the public :-)

Thanks again to you for all the help and suggestions.
Attached Files
File Type: zip Gimbolino-v0.1.zip (12.1 KB, 278 views)
gmarco is offline   Reply With Quote
Unread 11-16-12, 03:03 PM   #5
gmarco
Premium Member
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 97
- first little bug I have found: /gimb remove could not be launched in a macro.

"gimbolino unable to find category remove"


Uhm ... I think I should check the args parsing ... this unknown thing ! :-)

Any tips are welcome :-)
gmarco is offline   Reply With Quote
Unread 11-16-12, 05:36 PM   #6
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 1,007
I'm trying to find the problem too, but I'm not seeing it. I'm at work now, I'll have to run the code later and poke around in it.
__________________
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
SDPhantom is offline   Reply With Quote
Unread 11-17-12, 03:36 AM   #7
gmarco
Premium Member
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 97
Could it be due the fact that only category is parsed in the "SecureCmdOptionParse" function ? If I add the call also for args ...


SlashCmdList["GIMBOLINO"] = function(args)

local category=SecureCmdOptionParse(args);
local args=SecureCmdOptionParse(args);

if args:lower() == "help" then
print(prgname .. " commands");
print("/gimb help - This help");
print("/gimb remove - Dismiss an active pets");
print("/gimb - Random summon a pet from your complete collection");
print("/gimb <category> - Random summon a pet from your custom <category> ");
return;
end

if args:lower() == "remove" then
print(prgname .. " is dismiss the active companion");
DismissCompanion("CRITTER");
return;
end


if not category then
return;
end
etc etc....


In this way it seems to work... but is it fine ?

macro like:
/gimb [btn:2] rare; [mod:alt] funny; [mod:shift] remove;

Last edited by gmarco : 11-17-12 at 03:43 AM.
gmarco is offline   Reply With Quote
Unread 11-17-12, 04:10 AM   #8
gmarco
Premium Member
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 97
I also added a declaration of :

-- if categories.lua is not found
pets = {};

otherwhise it triggers an error if trying to summon from a category when the category.lua is missing.

Now it returns with "category not found message" much more friendly :-)

and modified the toc files in this way:

core.lua
categories.lua

if the order of definitions is important.


I think now it should be ready to be committed ...
Attached Files
File Type: zip Gimbolino-v0.1.zip (12.1 KB, 272 views)
gmarco is offline   Reply With Quote
Unread 11-17-12, 10:28 PM   #9
Phanx
A Pyroguard Emberseer
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 4,267
If you do this:
Code:
	local category=SecureCmdOptionParse(args);
	local args=SecureCmdOptionParse(args);
... then both category and args will have identical values.

After looking through your code, I see that you're currently creating a global named pets. This is a really bad idea, since pets is a very generic name, and any other addon that creates a global variable with the same name (even by accident) will overwrite it, breaking your addon (or theirs). I'd suggest using the "private namespace table" that all addons get nowadays. Put this at the top of each of your Lua files:

Code:
local _, pets = ...
Now pets is a table local to your addon, but accessible from all of your addon's files.

Also, your example macro in the comments in the addon file:

Code:
/gimb [btn:2] rare [mod:alt] funny [mod:shift] remove
... is incorrect. Remember, this needs to follow all the same rules as "real" macros, so each condition needs to be separated by a semicolon:

Code:
/gimb [btn:2] rare; [mod:alt] funny; [mod:shift] remove
Finally, you don't need a semicolon at the end of lines in Lua. Unless you're used to programming in another language where semicolons are required, and find the habit hard to break, I'd suggest getting rid of them to keep your code clean.

See attached file for these modifications, plus some general cleanup.
Attached Files
File Type: zip Gimbolino-v0.1.zip (11.9 KB, 280 views)
__________________
Author/maintainer of Grid, PhanxChat, ShieldsUp, and many more.
Troubleshoot an addonTurn any code into an addonMore addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please don’t PM me about addon bugs or code questions. Post a comment or forum thread instead!

Last edited by Phanx : 11-17-12 at 10:33 PM.
Phanx is offline   Reply With Quote
Unread 11-18-12, 06:10 AM   #10
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 1,007
I removed the LibPetJournal-2.0 library and converted the code to use the C_PetJournal API directly. I also made the code a bit more verbose as well as added the ability for the user to modify the categories in-game through the chat command system. Categories should now be saved across sessions too. The new code also uses an experimental method of unregistering the filter update event before setting them to what it needs, then resetting them to the previous settings before restoring the event. This should improve performance slightly since it'll prevent the filter update from running unnecessary code while Gambolino is trying to work.

Code:
Gimbolino usage
/gimb help - This help
/gimb dismiss - Dismiss an active pet
/gimb add <category> <pet> - Adds a pet to a category
/gimb remove <category> <pet> - Removes a pet from a category
/gimb delete <category> - Deletes a category
/gimb - Random summon a pet from your complete collection
/gimb <category> - Random summon a pet from your custom <category>
<< Download removed to conserve attachment space >>
__________________
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 04-19-13 at 03:31 PM.
SDPhantom is offline   Reply With Quote
Reply

Go BackWoWInterface » Developer Discussions » General Authoring Discussion » Compaions API broken ?

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