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
## Title: Garrison NPC
## Author: Etuliela
## Version: v1.0.0
## Notes: Tracks which NPCs are available in each of your characters' garrisons.
## SavedVariables: NpcData
garrisonnpc.lua
garrisonnpc.lua
Lua Code:
-- Table for saved variables
NpcData = {}
local EventFrame = CreateFrame("Frame")
-- Check player's level on login - if player is 100 it will record additional character information, otherwise it will not
EventFrame:RegisterEvent("PLAYER_LOGIN")
EventFrame.OnEvent = function(self,event,playerName,characterLevel)
playerName = UnitName("Player")
characterLevel = GetCharacterLevel(playerName)
if characterLevel == 100 then
NpcData.characterName = UnitName("Player")
NpcData.characterRealm = GetRealmName()
NpcData.characterAccount = THIS_ACCOUNT
ChatFrame1:AddMessage(NpcData.characterName, NpcData.characterRealm, NpcData.characterAccount)
end
end