Thread Tools Display Modes
10-24-10, 01:23 PM   #1
blinked
A Murloc Raider
Join Date: Apr 2009
Posts: 7
Is wowwiki tutorial out of date?

I tried creating the hello world basic mod by following directions on:
http://www.wowwiki.com/AddOn_program...l/Introduction

And here is my code for HelloWorld.toc

Code:
## Interface: 40000
## Title: Hello World!
## Notes: My first AddOn
HelloWorld.lua
HelloWorld.xml
HelloWorld.lua

Code:
function HelloWorld() 
  print("Hello World!"); 
end
HelloWorld.xml
Code:
<Ui xmlns="http://www.blizzard.com/wow/ui/" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xsi:schemaLocation="http://www.blizzard.com/wow/ui/ 
 ..\..\FrameXML\UI.xsd">
<Script File="HelloWorld.lua" />
<Frame name="HelloWorldFrame">
<Scripts>
<OnLoad>
	HelloWorld();
</OnLoad>
</Scripts>

</frame>
</Ui>
According to wowwiki, I should see "Hello World!" written in chatbox. I am looking for it but there is nothing in the chatbox. So I have a feeling I screwed up somewhere or the wowwiki page is out of date. Can one of you kind souls verify if its pebkac issue or something out of my hand?

Sorry if its in the wrong place.. I don't post here very often.
  Reply With Quote
10-24-10, 01:25 PM   #2
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
</Frame> is case sensitive
  Reply With Quote
10-24-10, 01:28 PM   #3
blinked
A Murloc Raider
Join Date: Apr 2009
Posts: 7
Originally Posted by p3lim View Post
</Frame> is case sensitive
That fixed it..

Darn now I feel dumb! This happens to me everytime and I can't point that mistake out myself.

thanks for pointing that out I appreciate it.
  Reply With Quote
10-24-10, 02:29 PM   #4
Xuerian
A Fallenroot Satyr
 
Xuerian's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 27
Originally Posted by blinked View Post
I tried creating the hello world basic mod by following directions on:
http://www.wowwiki.com/AddOn_program...l/Introduction

And here is my code for HelloWorld.toc
.....

According to wowwiki, I should see "Hello World!" written in chatbox. I am looking for it but there is nothing in the chatbox. So I have a feeling I screwed up somewhere or the wowwiki page is out of date. Can one of you kind souls verify if its pebkac issue or something out of my hand?

Sorry if its in the wrong place.. I don't post here very often.
Don't forget that you can skip the XML and simply:
Code:
function HelloWorld()
  print("Hello World from Lua!") -- semicolons are sugar only
end
HelloWorld()

-- And if you want the frame
local frame = CreateFrame("Frame", "HelloWorldFrame")

-- And set scripts, not that calling it again will help anything
frame:SetScript("OnLoad", HelloWorld)
  Reply With Quote
10-24-10, 02:51 PM   #5
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,325
Originally Posted by Xuerian View Post
Don't forget that you can skip the XML and simply:
Code:
function HelloWorld()
  print("Hello World from Lua!") -- semicolons are sugar only
end
HelloWorld()

-- And if you want the frame
local frame = CreateFrame("Frame", "HelloWorldFrame")

-- And set scripts, not that calling it again will help anything
frame:SetScript("OnLoad", HelloWorld)
Note, the OnLoad handler will not run if you define it in Lua as the event fires the instant CreateFrame is called.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
10-24-10, 03:17 PM   #6
Xuerian
A Fallenroot Satyr
 
Xuerian's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 27
Originally Posted by SDPhantom View Post
Note, the OnLoad handler will not run if you define it in Lua as the event fires the instant CreateFrame is called.
Shh, it isn't as fun if they don't start off good and confused
  Reply With Quote
10-24-10, 03:43 PM   #7
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 793
If you put "HelloWorld()" on the bottom (when all frame elements are loaded) it would be the same as "OnLoad" in the XML really.

Oh, also it seems like wowwiki moved to wowpedia.org -according to the "about" page at least... wonder if they will shut down wowwiki for good at some point (or make it hard redirect to the new site).

Last edited by Vlad : 10-24-10 at 03:53 PM.
  Reply With Quote
10-24-10, 04:50 PM   #8
blinked
A Murloc Raider
Join Date: Apr 2009
Posts: 7
For simple helloworld I don't think I need to call any frames it seems...

I can simply type "print ("Hello World!") in HelloWorld.lua and link the lua file in toc. I wouldn't even need xml file apparently or any functions or frames.


I love experimenting.

That being said, does createframe call OnLoad handler automatically as default?
  Reply With Quote
10-24-10, 05:01 PM   #9
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,325
Originally Posted by blinked View Post
That being said, does createframe call OnLoad handler automatically as default?
If one exists already, for example, from an inherited template.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
10-24-10, 05:22 PM   #10
blinked
A Murloc Raider
Join Date: Apr 2009
Posts: 7
Another question:
Anyone know the new linkType for linkable raid lockout by any chance?

I mean, I am creating a example mod where hovering over itemlinks in chat will create a tooltip on mouseover rather than clicking on it.

My current code, which is pretty much the same code from example mod provided from the tutorial book that I got if from library..
Code:
local function showTooltip(self, linkData)
	local linkType = string.split(":", linkData)
	if linkType == "item"
	or linkType == "spell"
	or linkType == "enchant"
	or linkType == "quest"
	or linkType == "talent"
	or linkType == "glyph"
	or linkType == "unit"
	or linkType == "achievement" then
		GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
		GameTooltip:SetHyperlink(linkData)
		GameTooltip:Show()
	end
end

local function hideTooltip()
	GameTooltip:Hide()
end

local function setOrHookHandler(frame, script, func)
	if frame:GetScript(script) then	-- check if it already has a script handler
		frame:HookScript(script, func) -- ...and hook it
	else
		frame:SetScript(script, func)	-- set our function as script handler otherwise
	end
end

for i = 1, NUM_CHAT_WINDOWS do
	local frame = getglobal("ChatFrame"..i) -- copy a reference
	if frame then --make sure that the frame exists
		setOrHookHandler(frame, "OnHyperLinkEnter", showTooltip)
		setOrHookHandler(frame, "OnHyperLinkLeave", hideTooltip)
	end
end
now this code works perfectly fine but I am looking for a linkType to put in for new raidlockout link they implemented in this patch.
  Reply With Quote
10-24-10, 09:40 PM   #11
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,325
Originally Posted by blinked View Post
Anyone know the new linkType for linkable raid lockout by any chance?
I haven't checked, but you should be able to obtain it by using a command like this...
Code:
/run print(("<Copy Link Here>"):match("\124H(.-)\124h"));


Originally Posted by blinked View Post
lua Code:
  1. local function showTooltip(self, linkData)
  2.     local linkType = string.split(":", linkData)
  3.     if linkType == "item"
  4.     or linkType == "spell"
  5.     or linkType == "enchant"
  6.     or linkType == "quest"
  7.     or linkType == "talent"
  8.     or linkType == "glyph"
  9.     or linkType == "unit"
  10.     or linkType == "achievement" then
  11.         GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
  12.         GameTooltip:SetHyperlink(linkData)
  13.         GameTooltip:Show()
  14.     end
  15. end
Honestly, you don't need to check if the string passed is a link if it's already known to be one.



Originally Posted by blinked View Post
lua Code:
  1. local function setOrHookHandler(frame, script, func)
  2.     if frame:GetScript(script) then
  3.         frame:HookScript(script, func)
  4.     else
  5.         frame:SetScript(script, func)
  6.     end
  7. end
You don't need to check for an existing script anymore, frame:HookScript() does the exact same thing as frame:SetScript() if there isn't one already.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 10-24-10 at 09:46 PM.
  Reply With Quote
10-24-10, 11:59 PM   #12
Xubera
A Cobalt Mageweaver
 
Xubera's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 207
its

\124Hinstancelock:GUID:RAIDID:0:BossesDowned\124h[Instance]\124h

for instance Ulduar is 603
bossesDowned is a counter pretty much, like if it were 0, no bosses are down, if its 1, the first boss is down, if its 2 the 2nd boss is down, if its 3 the first and 2nd boss are down, if its 4 only the 3rd boss is down

if you count it out in binary it make a lot more sense

Ulduar has 14 bosses giving it a maximum value of 16383 (16384 comboinations including 0)

example:
00000000000000 <-- 14 0s, 14 bosses. so lets say
00000001101001 <-- leviathan, XT, Korogan, and cat lady are all dead, in binary this number is 105

also the GUID is only used for the name of the persons lockout.

/run print("\124Hinstancelock:"..UnitGUID("player"):sub(3)..":603:0:105\124h[ulduar]\124h")
outputs a link for ulduar with your name as the lockout info. and as demonstrated 105 will have those bosses down.
__________________
Chat Consolidate is the solution to any out of control trade chat. Ignore lines, throttle chat, consolidate posts!Follow the link to find out how!

▲ ▲ WoWInterface wont let me triforce >.>

Last edited by Xubera : 10-25-10 at 12:06 AM.
  Reply With Quote
10-25-10, 07:50 AM   #13
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 793
Xubera since you know about bits and such, in many languages you can do a bit.band(105, 8) i.e. check if the 8th bit has a 1 or 0, if it's 1 you get anything but "0" returned thus you can do if not x then <you know it's 1> end checks.

My question is I played around with the bit.band but couldn't get it to work as expected. I tried using some other languages but there it works, hmm... it's odd. Got perhaps a suggestion of a simple function to check if certain flags are set to 1 or 0 by using the bit position as variable and the integer as the data to check?
  Reply With Quote
10-25-10, 10:21 AM   #14
blinked
A Murloc Raider
Join Date: Apr 2009
Posts: 7
Originally Posted by SDPhantom View Post
I haven't checked, but you should be able to obtain it by using a command like this...
Code:
/run print(("<Copy Link Here>"):match("\124H(.-)\124h"));
Thanks this worked like a charm. Apparently its instancelock and now everything works.



Honestly, you don't need to check if the string passed is a link if it's already known to be one.
I understand but I think that mod and its code is really old. But since I am learning lua along with wow mods


You don't need to check for an existing script anymore, frame:HookScript() does the exact same thing as frame:SetScript() if there isn't one already.
So the updated code would most likely be:
Code:
local function setOrHookHandler(frame, script, func)
	--if frame:GetScript(script) then	-- check if it already has a script handler
		--frame:HookScript(script, func) -- ...and hook it
	--else
		frame:SetScript(script, func)	-- set our function as script handler otherwise
	--end
end
I just commented out the conditional statements and it still works fine.

Last edited by blinked : 10-25-10 at 10:24 AM.
  Reply With Quote
10-25-10, 10:33 AM   #15
blinked
A Murloc Raider
Join Date: Apr 2009
Posts: 7
Originally Posted by Xubera View Post
its

\124Hinstancelock:GUID:RAIDID:0:BossesDowned\124h[Instance]\124h

for instance Ulduar is 603
bossesDowned is a counter pretty much, like if it were 0, no bosses are down, if its 1, the first boss is down, if its 2 the 2nd boss is down, if its 3 the first and 2nd boss are down, if its 4 only the 3rd boss is down

if you count it out in binary it make a lot more sense

Ulduar has 14 bosses giving it a maximum value of 16383 (16384 comboinations including 0)

example:
00000000000000 <-- 14 0s, 14 bosses. so lets say
00000001101001 <-- leviathan, XT, Korogan, and cat lady are all dead, in binary this number is 105

also the GUID is only used for the name of the persons lockout.

/run print("\124Hinstancelock:"..UnitGUID("player"):sub(3)..":603:0:105\124h[ulduar]\124h")
outputs a link for ulduar with your name as the lockout info. and as demonstrated 105 will have those bosses down.
Now I don't have much programming experience outside of introduction to java programming. (lol)

And I am still learning lua. That being said, I kinda understand the logic there. But what if you are trying to find other players information? Can you make bossesDowned a variable that we can extract the information from that player?

For now this is way beyond my league as I am only a newbie in learning lua. But I am very interested in making a mini mod where raid leader can check where his whole without having them linking their instancelocks.
  Reply With Quote
10-25-10, 03:25 PM   #16
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 793
Just trying to help explain:

Code:
local guid = UnitGUID("player"):sub(3) -- Current player GUID (faking your save)
local dungeonid = 603 -- Ulduar
local bossesDowned = "11111111111111111"
--[[                  ABCDEFGHIJKLMNOPQ -- imagine them as each one reference to one letter, 1 is dead and 0 is alive
A = Algalon the Observer
B = Auriaya
C = Flame Leviathan
D = Freya
E = General Vezax
F = Hodir
G = Ignis the Furnace Master
H = Kologarn
I = Mimiron
J = Razorscale
K = The Assembly of Iron
L = Thorim
M = TX-002 Deconstructor
N = Yogg-Saron
O = Elder Brightleaf
P = Elder Ironbranch
Q = Elder Stonebark
]]
local function visualBinaryToDecimal(str) -- just made this to turn the binary into a decimal number -you do NOT have to do it this way!
  local sum = 0
  for i=1, b:len() do
    if b:sub(i,i)=="1" then
      s = s + (2^(i-1))
    end
  end
  return s
end
print(format("\124Hinstancelock:%s:%d:0:%d\124h[Saved Test]\124h", guid, dungeonid, visualBinaryToDecimal(bossesDowned)))
Note:
1. There is no clear pattern, the most left or right digit does not mean first or last boss (this is a con as you wont know if player defeated the last boss or not, you have to keep a database over each dungeon and what their flags represent -lame!)

2. There are as many digits as there are bosses available (look at the raid save tooltip, each line is represented by a digit -this is a pro, as it's easy to find out the biggest value available. In Ulduar there are actually 17 boss flags so the max value that "bossesDowned" can have is 2^(17-1)=131071 (including where all bosses are alive, i.e. 0 while this value is when all are dead) Btw it's 2^16 because 17 would mean there are 18 bosses (don't get confused, just think number of lines in the tooltip, minus 1 that's what you power 2 by).

3. You can fake your saves like any other in-game link, I don't know if this is a pro or con.

A tip: look at ItemRef.lua in the FrameXML folder. You can see all the possible tooltips that you can send and receive. Also you could check how Blizz parses the text and finds out what's a link and not.

Last edited by Vlad : 10-25-10 at 03:33 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Is wowwiki tutorial out of date?


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off