Quantcast Clear chat slash command. - WoWInterface
 
Thread Tools Display Modes
08-31-15, 01:16 AM   #1
Lesteryoung
A Cliff Giant
Join Date: Aug 2015
Posts: 76
Clear chat slash command.

I'm trying to create a command function that simply clears the chat that you currently have selected, whether it be the combat log or the main chat or any other chat frame.

This is what I have, but the code is off.

Code:
SlashCmdList["CLEAR"] = function() SELECTED_CHAT_FRAME() end
	SLASH_CLEAR1     = "/clear"
  Reply With Quote
08-31-15, 02:10 AM   #2
Kkthnx
A Cobalt Mageweaver
 
Kkthnx's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2011
Posts: 244
Originally Posted by Lesteryoung View Post
I'm trying to create a command function that simply clears the chat that you currently have selected, whether it be the combat log or the main chat or any other chat frame.

This is what I have, but the code is off.

Code:
SlashCmdList["CLEAR"] = function() SELECTED_CHAT_FRAME() end
	SLASH_CLEAR1     = "/clear"
Try this.
Code:
SlashCmdList.CLEAR_CHAT = function()
	for i = 1, NUM_CHAT_WINDOWS do
		_G[format("ChatFrame%d", i)]:Clear()
	end
end
SLASH_CLEAR_CHAT1 = "/clear"
If you want to see some other ones look here.
https://github.com/Kkthnx/KkthnxUI/b...e/Commands.lua
__________________
Success isn't what you've done compared to others. Success is what you've done compared to what you were made to do.

Last edited by Kkthnx : 08-31-15 at 02:12 AM.
  Reply With Quote
09-01-15, 02:23 AM   #3
Petrah
A Pyroguard Emberseer
 
Petrah's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2008
Posts: 2,988
This is what I'm currently using. Someone shared it on a forum, I think it was the official forums, but I cannot recall who. I've been using it for quite a long time added in one of the files for ElvUI.

Code:
SlashCmdList["CLEAR"] = function()
    local s, i
    s = ""
    for i=1, 255, 1 do
        s = s..'\r'
    end
    SELECTED_CHAT_FRAME:AddMessage(s)
end
__________________
♪~ ( ) I My Sonos!
AddOn Authors: If your addon spams the chat box with "Addon v8.3.4.5.3 now loaded!", please add an option to disable it!
  Reply With Quote
09-01-15, 04:48 AM   #4
ObbleYeah
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Sep 2008
Posts: 210
seems kinda gross to add 255 blank messages rather than simply clearing them
  Reply With Quote
09-01-15, 05:54 AM   #5
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 427
Originally Posted by Petrah View Post
This is what I'm currently using. Someone shared it on a forum, I think it was the official forums, but I cannot recall who. I've been using it for quite a long time added in one of the files for ElvUI.

Code:
SlashCmdList["CLEAR"] = function()
    local s, i
    s = ""
    for i=1, 255, 1 do
        s = s..'\r'
    end
    SELECTED_CHAT_FRAME:AddMessage(s)
end
How about just doing this instead?
Lua Code:
  1. SlashCmdList["CLEAR"] = function()
  2.     SELECTED_CHAT_FRAME:Clear()
  3. end
__________________

Last edited by MunkDev : 09-01-15 at 05:59 AM.
  Reply With Quote
09-01-15, 07:00 AM   #6
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,257
http://wow.curseforge.com/addons/cle...earing-method/ (couple years back since I submitted this but I expect it still works)
  Reply With Quote
09-01-15, 02:47 PM   #7
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 1,906
Originally Posted by Dridzt View Post
Code:
SlashCmdList["CLEAR"] = SELECTED_CHAT_FRAME.Clear
SLASH_CLEAR1 = "/clear"
SLASH_CLEAR2 = "/chatclear"
http://wow.curseforge.com/addons/cle...earing-method/
(couple years back since I submitted this but I expect it still works)
That ends up passing the command arguments string as self, which should raise an error.
__________________
ESOUI AddOns | 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
09-02-15, 05:55 PM   #8
Lesteryoung
A Cliff Giant
Join Date: Aug 2015
Posts: 76
Been using MunkDev's version and it works fine. Is this the preferable way to clear chat? Obviously creating 255 blank lines seem egregious.

Only complaint is that it doesn't clear the combat log when it's selected. There's a code floating around on arenajunkies but it doesn't work either. They must have changed chat API within the last few years.
  Reply With Quote
09-02-15, 07:05 PM   #9
Kkthnx
A Cobalt Mageweaver
 
Kkthnx's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2011
Posts: 244
Originally Posted by Lesteryoung View Post
Been using MunkDev's version and it works fine. Is this the preferable way to clear chat? Obviously creating 255 blank lines seem egregious.

Only complaint is that it doesn't clear the combat log when it's selected. There's a code floating around on arenajunkies but it doesn't work either. They must have changed chat API within the last few years.
Have you even tried the one I posted? It does everything you've requested even the combat log?

Here I'll post it again and quote myself.

Originally Posted by Kkthnx View Post
Try this.
Code:
SlashCmdList.CLEAR_CHAT = function()
	for i = 1, NUM_CHAT_WINDOWS do
		_G[format("ChatFrame%d", i)]:Clear()
	end
end
SLASH_CLEAR_CHAT1 = "/clear"
If you want to see some other ones look here.
https://github.com/Kkthnx/KkthnxUI/b...e/Commands.lua
__________________
Success isn't what you've done compared to others. Success is what you've done compared to what you were made to do.
  Reply With Quote
09-02-15, 07:18 PM   #10
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,721
Originally Posted by Lesteryoung View Post
Been using MunkDev's version and it works fine. Is this the preferable way to clear chat? Obviously creating 255 blank lines seem egregious.

Only complaint is that it doesn't clear the combat log when it's selected. There's a code floating around on arenajunkies but it doesn't work either. They must have changed chat API within the last few years.
That's not MunkDev's code, that was Petrah's that he had quoted. And, no, creating 255 blank lines is not the best way. And the reason why it doesn't work in the combat log is because you can't add messages to it (to my knowledge, anyway).

Take another look at MunkDev's actual posted solution.


Originally Posted by Kkthnx View Post
Have you even tried the one I posted? It does everything you've requested even the combat log?

Here I'll post it again and quote myself.
The OP asked for a script to clear the currently selected chat window, not 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
09-02-15, 07:32 PM   #11
Kkthnx
A Cobalt Mageweaver
 
Kkthnx's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2011
Posts: 244
Originally Posted by Seerah View Post
That's not MunkDev's code, that was Petrah's that he had quoted. And, no, creating 255 blank lines is not the best way. And the reason why it doesn't work in the combat log is because you can't add messages to it (to my knowledge, anyway).

Take another look at MunkDev's actual posted solution.



The OP asked for a script to clear the currently selected chat window, not all at once.
Sigh, again he needs to use the one I posted. Who mentioned all at once?
__________________
Success isn't what you've done compared to others. Success is what you've done compared to what you were made to do.
  Reply With Quote
09-02-15, 07:33 PM   #12
Lesteryoung
A Cliff Giant
Join Date: Aug 2015
Posts: 76
Seerah, I did use MunkDev's code, and it work's fine on chat but doesn't clear the combat log.
The one kkthnx posted clears all chats, not the one you have selected.
And the one Petrah posted creates 255 blank lines which everyone has said is stupid.
  Reply With Quote
09-02-15, 07:35 PM   #13
Kkthnx
A Cobalt Mageweaver
 
Kkthnx's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2011
Posts: 244
Originally Posted by Lesteryoung View Post
Seerah, I did use MunkDev's code, and it work's fine on chat but doesn't clear the combat log.
The one kkthnx posted clears all chats, not the one you have selected.
And the one Petrah posted creates 255 blank lines which everyone has said is stupid.
The one I posted will not clear the combat log unless you have that focused.
__________________
Success isn't what you've done compared to others. Success is what you've done compared to what you were made to do.
  Reply With Quote
09-03-15, 06:48 AM   #14
Petrah
A Pyroguard Emberseer
 
Petrah's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2008
Posts: 2,988
Originally Posted by Seerah View Post
that was Petrah's that he had quoted
Just to clarify, that's not my code. I got it from someone who shared it a very very long time ago on the official forums.
__________________
♪~ ( ) I My Sonos!
AddOn Authors: If your addon spams the chat box with "Addon v8.3.4.5.3 now loaded!", please add an option to disable it!
  Reply With Quote
09-03-15, 09:39 AM   #15
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
The combat log entries are not stored in the message frame, so to speak, so it can be repopulated again. There seems to be a function CombatLogClearEntries() which sounds like it might do what you want.
__________________
Grab your sword and fight the Horde!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Clear chat slash command.

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