I just started playing WoW and as a computer science major and programmer by trade, the idea of writing mods was very intriguing. I am not going for anything advanced or even desireable right now, I just am trying to get the feel. I have experience with many other languages, OOP and scripting, but not Lua. I am currently reading up on Lua and making non-WoW programs, but I am interested in starting some WoW programming. I have done the basic Hello World tutorial, playing around with changing different parts of the code, but what I want to achieve next involves, I'm assuming, the GameTooltip: API. What I would like to achieve is to change the text for an item tooltip, when the user hovers over an item. For learning sake I am only trying to get it to add a set line of text to any item tooltip. A pseudo-code example

I am just wondering for WoW what events would trigger this in order to run the Lua script and what built in functions can achieve my desired result? I see functions such as GameTooltip:addLine(text), do these functions affect item tool tips? Or are they implemented only for user-defined frames from your xml or lua files? I mainly want this to work with items in bags, to make it easy for me to see it working for debugging purposes. Thank you for your time.

pocnib

Posted by pocnib on Thu, 23 Apr 2009 15:29:54

I just started playing WoW and as a computer science major and programmer by trade, the idea of writing mods was very intriguing. I am not going for anything advanced or even desireable right now, I just am trying to get the feel. I have experience with many other languages, OOP and scripting, but not Lua. I am currently reading up on Lua and making non-WoW programs, but I am interested in starting some WoW programming. I have done the basic Hello World tutorial, playing around with changing different parts of the code, but what I want to achieve next involves, I'm assuming, the GameTooltip: API. What I would like to achieve is to change the text for an item tooltip, when the user hovers over an item. For learning sake I am only trying to get it to add a set line of text to any item tooltip. A pseudo-code example

I am just wondering for WoW what events would trigger this in order to run the Lua script and what built in functions can achieve my desired result? I see functions such as GameTooltip:addLine(text), do these functions affect item tool tips? Or are they implemented only for user-defined frames from your xml or lua files? I mainly want this to work with items in bags, to make it easy for me to see it working for debugging purposes. Thank you for your time.

There is a script handler for the tooltip being set to display different types of things (items, quests, etc). You securely hook the OnTooltipSetItem function to catch a new item being displayed. But this handler can fire multiple times for certain types of items, so to ensure we only add the line once we clear a boolean flag OnTooltipCleared.

That's what it takes to add a line to the tooltip.

Posted by pocnib on Thu, 23 Apr 2009 17:27:06

Thank you so much for your prompt response. Just to make sure that I understand what the snippet you linked to does exactly...

Instantiate a local boolean variable. Since the scope is local whenever the UI gets reset (i.e. on logout) the variable loses its value. Create a user-defined function where if boolean is false, add the line of text and make boolean true, otherwise do nothing. Make another user defined function where the boolean is reset whenever a call is made to the WoW built-in event OnTooltipCleared. Map the two local, user-defined functions to their WoW built-in event counterparts of the same name.

Does this mean that no call to registerEvent is necessary? Or do I still need to register the OnTooltipSetItem and OnTooltipCleared events?

Sorry for so many questions but I am used to several other languages where small things like these can make a huge difference in whether or not the program works.

Also, does WoWProgramming have a link to the snippets section? I couldn't find that link anywhere aside from the hyperlink in the last post.

Posted by jnwhiteh on Fri, 24 Apr 2009 04:03:54

Instantiate a local boolean variable. Since the scope is local whenever the UI gets reset (i.e. on logout) the variable loses its value.

Not entirely. The local scope just means that it cannot be accessed by anything outside that scope. The scope of a variable really has no bearing on whether or not it is saved. Read the section of the book on SavedVariables for more information.

Create a user-defined function where if boolean is false, add the line of text and make boolean true, otherwise do nothing. Make another user defined function where the boolean is reset whenever a call is made to the WoW built-in event OnTooltipCleared. Map the two local, user-defined functions to their WoW built-in event counterparts of the same name.

Does this mean that no call to registerEvent is necessary? Or do I still need to register the OnTooltipSetItem and OnTooltipCleared events?

They are not events, they are script handlers. You should read the chapter on adding behavior to frames to better understand the difference.

Sorry for so many questions but I am used to several other languages where small things like these can make a huge difference in whether or not the program works.

Also, does WoWProgramming have a link to the snippets section? I couldn't find that link anywhere aside from the hyperlink in the last post.

Its on the main page of the site, yes. You can access it directly at http://wowprogramming.com/misc/snippets.