View Single Post
04/26/24, 03:53 AM   #11
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 5,009
Yes looks good
Added a few comments, hope it's understandable.
Maybe that helps you too:

Lua Code:
  1. function FarmersToolkit.BountyCheck()
  2.  
  3.         local CurBounty=GetFullBountyPayoffAmount(); --lua does not need the ; at line ends (allthough they raise no error)
  4.         local identifier="FarmersToolkit-BountyCheck";
  5.  
  6.         -- local reference variable to speed up things a bit. Can help if you access the same variables more than once.
  7.         -- Else it would each time completely search your table FarmersToolkit for the variable BountyValue again!
  8.         -- If you put a local reference it directly points there and can read and write that table's variable too
  9.         local FTbountyValue = FarmersToolkit.BountyValue
  10.  
  11.  
  12.         -- In case this is the first time we've been called this session...
  13.         FTbountyValue = FTbountyValue or 0 --checks if it's ot nil and uses itssself then, or else defaults it to 0
  14.  
  15.         if ( CurBounty == 0 ) then  -- We have no bounty, whew!
  16.                 if ( FTbountyValue > 0 ) then -- We may have a outstanding timer event tho
  17.                         EVENT_MANAGER:UnregisterForUpdate(identifier)
  18.                 end
  19.  
  20.                 FTbountyValue = 0; -- Zero out internal counter / tracker
  21.                 FarmersToolkit.UpdateActivities(); -- Update the screen
  22.                 dft_debug("BountyCheck indicates you are safe as of " .. os.time() .. "!"); -- Debug
  23.                 dft("Bounty appears cleared, cancelling timers - happy hunting."); -- Announce
  24.         else
  25.                 if ( ( FTbountyValue == 0 ) and ( CurBounty > 0 ) ) then -- This is the onset of a bounty
  26.                         dft("Bounty detected (" .. CurBounty .. "), updates posted to screen until cleared.");
  27.                 end
  28.                 FarmersToolkit.UpdateActivities();
  29.                 FTbountyValue=CurBounty;
  30.                 dft_debug("BountyCheck = " .. CurBounty .. ", timer set for 15 seconds as of " .. os.time());
  31.                 EVENT_MANAGER:UnregisterForUpdate(identifier)  -- Just in case
  32.                 EVENT_MANAGER:RegisterForUpdate(identifier, 15000, FarmersToolkit.BountyCheck)
  33.         end
  34.  
  35. end -- FarmersToolkit.BountyCheck
  Reply With Quote