Thread Tools Display Modes
02-10-09, 11:29 AM   #1
Bodur
A Murloc Raider
Join Date: Feb 2009
Posts: 4
Beyond "Hello World!"

Hello everyone,

Recently (ahem last weekend) I decided to join the ranks of those who write addons and found the "Hello World!" tutorial. I worked through that and it works. Great! Now I want to take the next step and use some function calls to make it more interesting.. Yay? No. I can't get the following code to work:

Bodur.toc file:
## Interface: 30000
## Title: Bodur
## Notes: My first AddOn
## Dependencies:
Bodur.lua
Bodur.xml


Bodur.lua file:
function HelloWorld()
message("Hello World!");

local s = "Hello everyone";

SendChatMessage("Hello Exodus", "GUILD");
SendChatMessage("Hello world", "SAY");
SendChatMessage("Hello everyone", YELL);

local index = GetChannelName("General") -- It finds General is a channel at index 1
if (index~=nil) then
SendChatMessage(s , "CHANNEL", nil, index);
end

SendChatMessage("Hello!", "WHISPER", "Common", "Lylmiss");

end


Bodur.xml file:
<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">
<Frame name="HelloWorldFrame">
<Scripts>
<OnLoad>
HelloWorld();
</OnLoad>
</Scripts>
</Frame>
</Ui>


It appears that the function calls to SendChatMessage are not working. None of the above combinations work. On the other hand, the function call to message() works fine. I am sure there is something obvious I am missing. Any ideas?

take care,
Bodur
  Reply With Quote
02-10-09, 11:58 AM   #2
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
My only thought is that it's too early to call SendChatMessage if you do it in a frames's OnLoad that's getting created at login. Perhaps consider creating a /command to call your function instead...

Code:
<OnLoad>
   HELLOWORLD_OnLoad()
</OnLoad>

-------

function HELLOWORLD_OnLoad()
     SlashCmdList["HELLOWORLD"] = "/helloworld"
     SLASH_HELLOWORLD1 = HelloWorld()
end
  Reply With Quote
02-10-09, 12:38 PM   #3
Gimbli
Premium Member
AddOn Author - Click to view addons
Join Date: Jan 2009
Posts: 15
Try changing it from an "OnLoad" function to an "OnEvent" function and register PLAYER_ENTERING_WORLD. OnLoad, you're going to run into issues obtaining UI and Game Engine information because things are in an initializing state.
  Reply With Quote
02-10-09, 12:43 PM   #4
hypehuman
A Deviate Faerie Dragon
 
hypehuman's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 17
Have you tried typing "/script HelloWorld()" in the chat box after you've logged in? If that works, then the above posters' suggestions should help.
  Reply With Quote
02-10-09, 01:11 PM   #5
Bodur
A Murloc Raider
Join Date: Feb 2009
Posts: 4
Smile

Thanks for all the suggestions. I will try them out as soon as the servers come back up.

In the line
SLASH_HELLOWORLD1 = HelloWorld()
should the "1" be there?

take care,
Bodur
  Reply With Quote
02-10-09, 01:52 PM   #6
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
Originally Posted by Bodur View Post
Thanks for all the suggestions. I will try them out as soon as the servers come back up.

In the line
SLASH_HELLOWORLD1 = HelloWorld()
should the "1" be there?

take care,
Bodur
Yes, although I completely screwed up other parts of it (I'm at work and thinking about other things :P)

It should be:

Code:
     
SlashCmdList["HELLOWORLD"] = HelloWorld
SLASH_HELLOWORLD1 = "/helloworld"
with no () on the function and the values swapped.

The reason for the 1 is that you can create additional /commands that will call the same function but won't override another addon's if their number is lower, for example if you wanted /hw to work as well, unless another addon used /hw as its only command, you could then do:

Code:
SLASH_HELLOWORLD2 = "/hw"

Last edited by Akryn : 02-10-09 at 01:59 PM.
  Reply With Quote
02-10-09, 04:40 PM   #7
Bodur
A Murloc Raider
Join Date: Feb 2009
Posts: 4
Talking

Thank you Akryn. This new version works!

And you were right, Hypehuman. It can also be called in-game as a script. Thanks.

Gimbli, can you elaborate a little about how to register PLAYER_ENTERING_WORLD? I am very new to both Lua and the Blizzard API.

take care,
Bodur
  Reply With Quote
02-10-09, 08:11 PM   #8
hypehuman
A Deviate Faerie Dragon
 
hypehuman's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 17
I learned how to use events from this wowwiki tutorial: http://www.wowwiki.com/Events_%28API...vent_reception
  Reply With Quote
02-10-09, 08:46 PM   #9
Mera
Retired of WoW, In ESO :)
 
Mera's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 331
Originally Posted by Bodur View Post
Thank you Akryn. This new version works!

And you were right, Hypehuman. It can also be called in-game as a script. Thanks.

Gimbli, can you elaborate a little about how to register PLAYER_ENTERING_WORLD? I am very new to both Lua and the Blizzard API.

take care,
Bodur
local event = CreateFrame("Frame") --not real frame but something that could detect event
event:SetScript("OnEvent", myFunc) -- myFunc() function called on event
event:RegisterEvent("PLAYER_ENTERING_WORLD") -- after which event myFunc() is called

not that PLAYER_LOGIN is preferred than PLAYER_ENTERING_WORLD because some api function could return nil values before player_login.
  Reply With Quote
02-10-09, 08:55 PM   #10
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Since they're using an xml file, they don't need to create an extra frame, and they can do the event registration/function call in their xml file.

In the OnLoad section, use self:RegisterEvent("PLAYER_ENTERING_WORLD") (or you can use "PLAYER_LOGIN" - see this: http://www.wowwiki.com/Events_that_f...oading_process). Then have an OnEvent section below that for your frame's scripts and put HelloWorld() or whatever function you wish to call. Just like the page that hypehuman linked you above.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
02-10-09, 09:18 PM   #11
Mera
Retired of WoW, In ESO :)
 
Mera's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 331
he should know both methods so then he can see in just 3 lua lines he can do more than a ugly xml file, my opīnion,just stay away from using that useless file format in wow. what does it make just is it shows things harder to code than they are

Last edited by Mera : 02-10-09 at 09:21 PM.
  Reply With Quote
02-10-09, 09:41 PM   #12
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
I prefer lua, too, but he was working off of a tutorial. Most all tutorials, even the Blizzard ones use an xml file to begin with. It's already all set up for him, he's getting the hang of it. He can take the next step later instead of being pushed into the pool all at once.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
02-12-09, 08:27 PM   #13
Bodur
A Murloc Raider
Join Date: Feb 2009
Posts: 4
All of you are GREAT help! Thank you very much. I am working on trying the various suggestions to see the effects.

take care,
Bodur

PS I guess getting pushed off the deep end is OK as long as you don't also push my head under.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Beyond "Hello World!"


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