11/19/14, 01:52 PM | #1 | |
Join Date: Nov 2014
Posts: 3
|
Help for new addon programer
Hi guys,
I'm totally new in lua and addon programming. I'm trying to make my first addon but getting an ui error 'checking type on argument callback failed in ScriptEventManagerRegisterforEventlua stack traceback: [C]:addons/.... .lua 53 in function 'Initialize'. I googled it but couldn't find anything do u know why i am getting this error. Thanks. |
|
11/19/14, 03:04 PM | #2 |
|
EVENT_MANAGER:RegisterForEvent("SomeGloballyUniqueString_PrefereablyYourAddonName", EVENT_CODE, callback)
callback must be a function, you're passing something else. Can't tell you more atm, error message is not enough, you'll need to give us the code that leads to it |
11/19/14, 03:28 PM | #3 | |
Join Date: Nov 2014
Posts: 3
|
oh sorry,but it is shame to share this bad algorithm and codes as i told this is my first addon and i did it for myself
Code:
local junker = { name = "junker" } local junk_types = { "ITEMTYPE_ADDITIVE", "ITEMTYPE_ALCHEMY_BASE", "ITEMTYPE_AVA_REPAIR", "ITEMTYPE_CLOTHIER_BOOSTER", "ITEMTYPE_CLOTHIER_MATERIAL", "ITEMTYPE_CLOTHIER_RAW_MATERIAL", "ITEMTYPE_COLLECTIBLE", "ITEMTYPE_CONTAINER", "ITEMTYPE_DISGUISE", "ITEMTYPE_ENCHANTING_RUNE", "ITEMTYPE_ENCHANTMENT_BOOSTER", "ITEMTYPE_FLAVORING", "ITEMTYPE_FOOD", "ITEMTYPE_GLYPH_ARMOR", "ITEMTYPE_GLYPH_JEWELRY", "ITEMTYPE_GLYPH_WEAPON", "ITEMTYPE_INGREDIENT", "ITEMTYPE_LURE", "ITEMTYPE_NONE", "ITEMTYPE_PLUG", "ITEMTYPE_RAW_MATERIAL", "ITEMTYPE_STYLE_MATERIAL", "ITEMTYPE_TRASH" } local junkarmor_types ={ "ARMORTYPE_LIGHT", "ARMORTYPE_MEDIUM", "ARMORTYPE_NONE" } local name = "junker" local function Initialize() EVENT_MANAGER:RegisterForEvent(name,EVENT_INVENTORY_SINGLE_SLOT_UPDATE,junkJunk) end local function OnAddOnLoaded(event,addonName) if addonName == "junker" then Initialize() end end local function junkJunk(eventCode,bagId,slotId,isNewItem,itemSoundCategory, updateReason) local armor_type = nil item_type = GetItemType(bagId,slotId) local item_link = GetItemLink(bagId,slotId) if item_type == "ITEMTYPE_ARMOR" then local armor_type= GetItemLinkArmorType(item_link) end if contains(junk_types,item_type) or contains(junkarmor_types,armor_type) then SetItemIsJunk(bagId,slotId) d("junked") end end local function contains(junk_types, element) for _, value in pairs(junk_types) do if value == element then return true end end return false end EVENT_MANAGER:RegisterForEvent("junker",EVENT_ADD_ON_LOADED,OnAddOnLoaded) |
|
11/19/14, 04:09 PM | #4 |
Local function "junkJunk" must be defined before line where it is called. Fixed code:
lua Code:
If you want also make this code a bit faster, do not use function "contains", but define your tables as follows and just check if table keys exists: Lua Code:
Last edited by Garkin : 11/19/14 at 04:15 PM. |
|
11/19/14, 04:20 PM | #5 |
|
Lua Code:
edit: but neither will do what you need, see below, circonian has it right Last edited by merlight : 11/19/14 at 05:16 PM. |
11/19/14, 05:01 PM | #6 |
|
In this code:
Lua Code:
GetItemType(bagId,slotId) could return ITEMTYPE_ARMOR if the item is a piece of armor, but ITEMTYPE_ARMOR is actually an integer, so you can't compare it to a string with: Lua Code:
You might want to change your tables to something like this: Lua Code:
Then when your trying to determine if something is junk or not you don't need to call an extra contains(...) function. you can just check that table to see if it is true/false (junk or not junk) Lua Code:
Oh and so the other part of your code would have to be changed to: Lua Code:
Last edited by circonian : 11/19/14 at 05:09 PM. |
11/19/14, 05:17 PM | #7 | |
Ah, circonian is right. I didn't think about what should be in the table. Tables should be defined as circonian said.
Lua Code:
Last edited by Garkin : 11/19/14 at 05:23 PM. |
||
11/19/14, 05:50 PM | #8 | |
|
Oh yeah, I didn't catch that one, I just copied what he had and took the ""s off Hes right, if you do Lua Code:
Depending upon what your going to do with it, you may or may not need it outside of that if statement. If you do then you'll have to do what he said. Lua Code:
Last edited by circonian : 11/19/14 at 06:06 PM. |
|
11/20/14, 01:34 AM | #9 | |
Join Date: Nov 2014
Posts: 3
|
guys i m realy gratefull for your interest, thanks it was really helpfull and instructive. now thanks to u i have my own addon
|
|
ESOUI » Developer Discussions » Lua/XML Help » Help for new addon programer |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|