Seeking help with first addon
Edit: Problem solved (sort of), might keep this thread handy in case any other issues pop up later. Thanks guys!
Hi! This is my first time trying to make an addon with Lua- the idea I am working towards is something that will keep track of the NPCs that are available in all of your alts' garrisons. To start with I tried to check the character's level when they log in and only check other information such as their name/class/realm if they are level 100. Mostly just as an experiment I wanted to try and print this to the user's chat frame after collecting this information, however despite fiddling with my code for a few hours I can't seem to manage to get it to work. My code is below- any advice would be greatly appreciated. Thanks! --- GarrisonNPC.toc Code:
## Interface: 60100 Lua Code:
|
Hi Etul.
Further information about the issue you encounter (e.g. which error message you get or, more general, what makes you think that the addon doesn't work) would be nice. Since I'm just a beginner with lua and addon-programming, it's highly likely that I've overlooked something, but after reading your code several times (and under the assumption that this is indeed all of your code) my only guess is the following: Code:
ChatFrame1:AddMessage(NpcData.characterName, NpcData.characterRealm, NpcData.characterAccount) Code:
ChatFrame1:AddMessage(NpcData.characterName) Code:
ChatFrame1:AddMessage(NpcData.characterName .. " " .. NpcData.characterRealm .. " " .. NpcData.charakterAccount) Cheers, Odjur |
Your problem is that you have registered an event and all, but there is nothing happening when it triggers. What you need is EventFrame:SetScript("OnEvent", your function).
|
Thanks for the help guys, it's really appreciated. :)
I added the SetScript part and finally managed to get it to print to chat with the following: Lua Code:
However it did print out on separate lines like this: [22:32:49] Sillycoder [22:32:49] Barthilas Next step is to work out how to get it to print to the same line, but I'm just happy that I finally managed to get my addon to actually DO something tangible. >.< Seems like this will be a very steep learning curve, but it will be a very interesting journey! (and a long one, too) |
Hi!
I already gave you a hint how to print in one line. :-) Code:
DEFAULT_CHAT_FRAME:AddMessage("Charactername: " .. NpcData.characterName .. " " .. "Characterrealm: " .. NpcData.characterRealm) Cheers, Odjur |
Quote:
|
Quote:
|
print is handy to use instead of DEFAULT_CHAT_FRAME:AddMessage. Not only because it's quicker (to type), but it also takes and prints multiple arguments.
Code:
print(NpcData.characterName, NpcData.characterRealm) |
I don't understand... How is your code working? And how did no one point this out?
There is no such function in WoW called GetCharacterLevel. It's just UnitLevel. /edit: and "Player" =/= "player" /edit2: both of these errors would have been pointed out to you if you have Lua errors enabled in your Interface Options. |
Quote:
|
/shrug I dunno. I Googled the function name and the only thing I could find was for NWN.
|
Oh wow... I wasn't expecting this thread to explode overnight, though I do appreciate all of you adding your input. I almost don't know where to start.
Quote:
Quote:
Quote:
I realised that I probably need to reverse the process and scan for the appropriate NPCs before recording any data so I will probably end up making arrays within something like NPCData[harrison] to store the player info. I don't know if it will make things less confusing then. ;) |
Quote:
@Seerah/10leej - I honestly can't remember where exactly I found the GetCharacterLevel() thing- iirc I couldn't find anything on wowiki/wowprogramming so I tried looking to see what people did in actual addons to find out a character's level and ended up with that. I think my mistake was using Ctrl+F to search for "character" which is why I would have missed it on wowprogramming. But I did manage to find the UnitLevel("player") thing somewhere else so I finally got my code working using that. :) Also, I tried running /dump UnitLevel("player") and /dump UnitName("player") with both capitalized and non-capiltalized versions of "player" and it returned the same result. |
All times are GMT -6. The time now is 12:06 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI