Help with a tiny addon

I’m not exactly sure if this is the kind of thing that you can get help with here, if not just let me know where to go! Trying to make a small addon that will check if someone who joined a raid is also on my friend’s list, and if so, change their friend note to the character they were playing and the date/time. I get a lot of people on my friend’s list from weekend pug fun runs that I host, and I’d like to know if somebody added me and then hasn’t come back in 2 months or more so I can remove them.

I gotta say I have a lot of respect for anyone who writes addons, doing programming without a proper debugger is the pits. That said, I’m happy doing debugging with comments and prints, but I seem to be missing whatever is necessary to get this to fire at all.

Thanks for any help!

local frame = CreateFrame("FRAME"); --create a frame for all of this

frame:RegisterEvent("RAID_ROSTER_UPDATE");  --can't seem to find good documentation on events, I want this to fire when someone new joins the 
frame:RegisterEvent("GROUP_ROSTER_UPDATE"); --trying anything I can, planned to narrow things down 
frame:RegisterEvent("GROUP_FORMED"); 
frame:RegisterEvent("INSTANCE_GROUP_SIZE_CHANGED"); 
frame:RegisterEvent("GROUP_JOINED"); 

frame:SetScript("OnEvent", rosterUpdate); --when RAID_ROSTER_UPDATE happens, fire the below function if i understand correctly (doubtful)

local function rosterUpdate(self, event, ...) --not quite sure what the dots are for, seems to be any given event has multiple arguments that come with it
	print("The event is registering and calling the function");
	
	local members = GetNumGroupMembers(); --get how many people are in the raid
	print(members); --testing
	
	C_FriendList.ShowFriends(); --update my friend info
	local numOnline = C_FriendList.GetNumOnlineFriends(); --get how many friends are online
	print(numOnline); --testing
	
	for i = 1, members do --for each raid member, get their character name from their position on the roster
		local characterNameInRaid = GetRaidRosterInfo(i); 
		print(characterNameInRaid); --testing
		for j = 1, numOnline do -- for each friend online inside the members on line loop, 
			local friendInfo = C_FriendList.GetFriendInfoByIndex(j) 
			--get that friends info which returns in a struct so we can access character name by friendlist info
			--saw alternate versions of functions specifically relating to BNet so not sure if C_FriendList.name returns *character* names, but can debug that later
			print(friendInfo.name); --testing
			if characterNameInRaid == friendInfo.name then --test the character in the raid vs the character on my friends list, and if they match
				found = C_FriendList.SetFriendNotesByIndex(j, characterNameInRaid .. " - " .. C_DateAndTime.GetCurrentCalendarTime()); 
				--update the friend note with the character they played and the date we were in the same group
				print(found); --testing
			end	
		end
	 end	
end

For debugging, install
https://www.curseforge.com/wow/addons/bugsack
and
https://www.curseforge.com/wow/addons/bug-grabber

Anything defined as local (like rosterUpdate) must be declared in code BEFORE it is called (move it above local frame = CreateFrame(...))

I’ve had bugsack and bug-grabber forever, but putting the function above the function call was what I needed to have it run and start giving me useful errors! Thanks a ton! It appears to work, but I still have a few lines of debugging for when I get a raid together this weekend.

local function rosterUpdateLTWP(self)	
	local members = GetNumGroupMembers(); --get how many people are in the raid
	
	C_FriendList.ShowFriends(); --update my friend info
	local _, numOnline = BNGetNumFriends(); --get how many friends are online		
	
	for i = 1, members do --for each raid member, get their character name from their position on the roster
		local characterNameInRaid = GetRaidRosterInfo(i); 			
		local dashPresent = string.find(characterNameInRaid, "-");
		
		if dashPresent then 
			characterNameInRaid = string.sub(characterNameInRaid, 1, (string.find(characterNameInRaid, "-") - 1));
		end
		
		for j = 1, numOnline do -- for each friend online inside the members on line loop,				
			local BNID, _, _, _, cName = BNGetFriendInfo(j); --get the bnet id for the session, and what character they are playing if any
			if cName ~= nil then print("index " .. j .. " playing " .. cName); end
			
			if characterNameInRaid == cName then --test the character in the raid vs the character on my friends list, and if they match
				local d = C_DateAndTime.GetCurrentCalendarTime(); --get date table
				local varDate = dateTable.month .. "/" .. dateTable.monthDay .. "/" .. dateTable.year; --get values from date table to make date string
							
				BNSetFriendNote(BNID, characterNameInRaid .. " - " .. varDate); --update the friend note with the character they played and the date we were in the same group
				print(characterNameInRaid .. " updated"); --testing				
				
				break;
			end	
		end
	 end	
end

local frame = CreateFrame("FRAME"); --create a frame for all of this	
frame:RegisterEvent("GROUP_ROSTER_UPDATE");	
frame:SetScript("OnEvent", rosterUpdateLTWP); --when GROUP_ROSTER_UPDATE happens, fire away

Also ended up making a quick script to set everybody’s note to todays date:

/run local all = BNGetNumFriends(); for i = 1, all do local bnid = BNGetFriendInfo(i); BNSetFriendNote(bnid, “6/20/19”); end

Thanks again