How to write to a file in wow addon





World of Warcraft
UI and Macro
Can an addon write to a log file?
The World of Warcraft community forums have moved!
These forums are in read-only mode. Please visit the new World of Warcraft community forums at

Can an addon write to a log file?

<God Tier>
110 Human Mage
3138 posts
Dec 12, 2015
Does wow allow addons to write data to a txt file for example?

100 Gnome Priest
4654 posts
Dec 12, 2015
Not directly. All file i/o is removed from addons.

However, an addon can tag a variable to be saved in the SavedVariables folder under the addon’s name. An addon can tag it to save in a global file or a per-character file.

And this variable can record stuff over time to create a log. (It’s how addons can keep track of stuff over time)

While this file can’t be forced into a format immediately recognizable to an outside program (unless it reads lua files), there may be an ODBC written up for doing this to convert to Access or maybe a csv for Excel or something.

<God Tier>
110 Human Mage
3138 posts
Dec 12, 2015
Any chance you could link me to what you are talking about?

Every page I looked at has a common theme: Blizzard won’t allow io because of bots.

Never even heard a mention about what you just said.

100 Gnome Priest
4654 posts
Dec 12, 2015
I don’t know if this would qualify as a link for this intended purpose but:

It’s easier to explain by example. Create the two files named in bold in a folder called TargetLog under AddOns:

## Interface: 60200
## Title: TargetLog
## Notes: Uses SavedVariables to log targets across multiple sessions
## SavedVariables: TargetLogData

TargetLogData = {} — initial value (will be overwritten when/if SavedVariables load)
local f = CreateFrame(“Frame”)
if UnitExists(“target”) then
local name = UnitName(“target”)
local level = UnitLevel(“target”)
local health = UnitHealthMax(“target”)
— adds date/time,name,level,health of target to TargetLogData

The next time you log in, as you target stuff, it gathers a few bits of info about your target and adds it to a table (TargetLogData). This data will accumulate across sessions (the purpose of SavedVariables is to keep stuff between sessions).

Note the ## SavedVariables: TargetLogData in the .toc. This is where you tag a variable to save. Then the addon itself fills the variable (almost always a table) with stuff.

Now when you logout or reload (and ONLY when you logout or reload–addons can’t control when this stuff writes beyond forcing a /reload which a user is generally not going to want while they play), the contents of TargetLogData is saved to the file WTF\Account\%accountname%\SavedVariables\TargetLog.lua. This is a text file that looks like:

TargetLogData = {
“12/12/15 00:19:57,Lunarfall Infantry,100,195708”, — [1]
“12/12/15 00:19:59,Muradin Bronzebeard,100,29356200”, — [2]
“12/12/15 00:20:02,Deedree,90,17503”, — [3]
“12/12/15 00:20:05,Captain Towix,100,97854”, — [4]
“12/12/15 00:20:06,Officer Jeor,100,97854”, — [5]
“12/12/15 00:20:08,Alliance Sailor,100,1467810”, — [6]
“12/12/15 00:20:09,Lieutenant Thorn,94,63226”, — [7]
“12/12/15 00:20:11,Shield Captain Chien,100,97854”, — [8]
“12/12/15 00:20:13,Sentinel Dawnshadow,100,97854”, — [9]
“12/12/15 00:20:15,Ro,100,385260”, — [10]
“12/12/15 00:20:18,Lunarfall Infantry,100,195708”, — [11]
“12/12/15 00:20:19,Porter,2,50”, — [12]
“12/12/15 00:20:22,Seer Kazal,100,97854”, — [13]
“12/12/15 00:20:24,Aenir,90,14002”, — [14]
“12/12/15 00:20:25,Squiggy,90,35006”, — [15]
“12/12/15 00:20:27,Rooter the Ravenous,100,146781”, — [16]
“12/12/15 00:20:28,Lio the Lioness,98,65312”, — [17]
“12/12/15 00:20:29,Quintessence of Light,25,788”, — [18]

This is a lua table of the data saved. When you log in later, part of the addon loading process is to run any existing SavedVariables files, so the table you saved on last logout is created with previous data on next login.

That is the complete and total extent that addons are allowed to write files.

An addon cannot change the structure of this file. The table name and syntax (table = { stuff, stuff, stuff, etc }) is there so it can be run. An addon has no control over this. The game creates it for its own purpose and makes no accomidation for outside programs to read it. If they ever change the structure of this file it would probably be to encrypt it so outside programs can’t use it.

To use it as a log for an outside program would require massaging this text to remove the syntax stuff to get a CSV or whatever format you choose. And it’s important to remember that this stuff only writes on a logout/reload. They don’t want it writing in realtime to prevent outside programs from learning about what’s going on in the game.

<God Tier>
110 Human Mage
3138 posts
Dec 12, 2015
Join the Conversation
Have something to say? Log in to join the conversation.
Thanks for visiting the Blizzard Forums (3.8.2) · Patch Notes
All trademarks referenced herein are the properties of their respective owners.

How classic addon spy find nearby pl ?

  • 所有注册的事件:


  • 关键函数

function Spy:ShowAlert(type, name, source, location)   in  MainWindow.lua

function Spy:AlertProwlPlayer(player)                                   in  List.lua

function Spy:CombatLogEvent(…)                                            in Spy.lua

判断 level :  用这个函数

function Spy:ParseUnitAbility(analyseSpell, event, player, flags, spellId, spellName)                                  In :   List.lua


  • 启动顺序

在 spy.xml 的 OnUpdate 事件中: 指定了当update发生时的执行函数

之后执行到 Spy.lua 的:

GameTooltipTextLeft1 这个是 wow 自带函数 ,功能是 :  Google GameTooltipTextLeft1  或者 GameTooltipTextLeft1  函数


To see it’s effects try this:

Now, view any tooltip. You will see the text on the first line of the tooltip fade out as it approaches 40 pixels from the left. To set the tooltip back use: