Reply
Thread Tools Display Modes
Unread 12-28-12, 08:02 PM   #1
Gehn47
A Murloc Raider
Join Date: Jan 2012
Posts: 6
Smile SendChatMessage question.

Ok so im writing a simple script to use a guild recruitment macro for my guild. My guild is spread across like 8 realms with each guild at a various different level.

so basically what i was thinking is declaring a variable for GetGuildLevel and then writing a simple print command. However im not sure if i should use the print command or SendChatMessage command and if I use the SendChatMessage command, can i insert a variable into the parameters and if i use the print command, how do I output to the default chat channel, for example, trade in cities, general everywhere else?

Thanks for the help.
Gehn47 is offline   Reply With Quote
Unread 12-28-12, 09:58 PM   #2
Gehn47
A Murloc Raider
Join Date: Jan 2012
Posts: 6
ok so basically

SLASH_DISCORD1, SLASH_DISCORD2 = '/discord', '/dc';
function SlashCmdList.DISCORD(msg, editbox)
gl = GetGuildLevel()
SendChatMessage("<Discord>("gl") is recruiting all levels. We are a social leveling guild with 7 bank tabs, website, vent & years of exp. So if you want help leveling, raiding, or just want to socialize, pst. We have a guild repair fund. Pst for invite.", "channel",nil,1)

Whats wrong here.

and is it possible to use GetChannel Name and an if/then statement to output to trade in city and general not in city?
Gehn47 is offline   Reply With Quote
Unread 12-28-12, 10:17 PM   #3
Phanx
A Pyroguard Emberseer
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 4,437
Please use [code] tags around your code so it's actually readable. I'm not sure how you're formatting your actual Lua file, but once proper formatting is applied to the code you posted, there are several glaringly obvious problems:

Code:
SLASH_DISCORD1, SLASH_DISCORD2 = '/discord', '/dc';
function SlashCmdList.DISCORD(msg, editbox) 
	gl = GetGuildLevel()
	SendChatMessage("<Discord>("gl") is recruiting all levels. We are a social leveling guild with 7 bank tabs, website, vent & years of exp. So if you want help leveling, raiding, or just want to socialize, pst. We have a guild repair fund. Pst for invite.", "channel",nil,1)
1) You're missing an "end" for your slash command handler function.

2) You're missing string concatenation operators around the "gl" variable you're trying to insert into the middle of your string.

Both of those problems are triggering Lua errors; enabling Lua error display -- or better yet, installing a dedicated error display addon like BugSack -- is the first thing you should do when trying to write or even just edit an addon. Without an error display, you are working blind.

Also, you don't actually need a variable, since you can just concatenate the result directly -- "<Discord>(" .. GetGuildLevel() .. ") is recruiting..." -- but if you want to use one anyway, it should absolutely not be a global variable, and absolutely should be a local one.

I'd also suggest picking one style of string delimiter -- single quotes or double quotes -- and use it consistently. Double quotes are more popular, since apostrophes are more likely to be in the middle of a string, either one is fine.

Finally, I'm not 100% sure, but the channel name (eg. "CHANNEL") passed to SendChatMessage may need to be capitalized; even if it's not required, you should do it anyway to maintain consistency with the official API usage in Blizzard's code and the API documentation on places like Wowpedia (which follows Blizzard's usage).

Here is your code revised to address the above issues and preferrentially send to the Trade channel when possible.

Code:
SLASH_DISCORD1, SLASH_DISCORD2 = "/discord", "/dc"
function SlashCmdList.DISCORD(msg, editbox)
	local _, _, _, _, _, active = GetChannelDisplayInfo(2)
	SendChatMessage("<Discord>(" .. GetGuildLevel() .. ") is recruiting all levels. We are a social leveling guild with 7 bank tabs, website, vent & years of exp. So if you want help leveling, raiding, or just want to socialize, pst. We have a guild repair fund. Pst for invite.", "CHANNEL", nil, active and 2 or 1)
end
In actual usage, though, you may want to do a little more work to make sure that channels 1 and 2 are actually General and Trade, since it isn't guaranteed that they will be.

Finally, your message seems a little wordy; I'd suggest trying to shorten it as much as possible. The less people have to read, the more likely they are to read at all.
__________________
Author/maintainer of Grid, PhanxChat, ShieldsUp, and many more.
Troubleshoot an addonTurn any code into an addonMore addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please don’t PM me about addon bugs or code questions. Post a comment or forum thread instead!
Phanx is offline   Reply With Quote
Unread 12-28-12, 10:28 PM   #4
Gehn47
A Murloc Raider
Join Date: Jan 2012
Posts: 6
Wow

Thanks so much for the help, some of these errors are obvious ones. Ive been up since 4 this morning and everything was starting blend together.
Gehn47 is offline   Reply With Quote
Reply

Go BackWoWInterface » AddOns, Compilations, Macros » Macro Help » SendChatMessage question.

Thread Tools
Display Modes

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