Thread Tools Display Modes
02-02-20, 02:16 PM   #1
Nodos7
A Murloc Raider
 
Nodos7's Avatar
Join Date: Feb 2020
Posts: 4
Delayed message in chat

Hello, world!
I have this simple code:
Code:
function ButtonHelp_OnClick()
	if UnitIsPlayer("target") or UnitName("target") == nil then
    SendChatMessage("I need help!");
    SendChatMessage("Somebody, help!");
    else
	SendChatMessage("Help me, target!");
        SendChatMessage("Target, please!");
    end
end
How can I send a second message after first message in 3 seconds? Is there any timer for this in vanilla wow?
  Reply With Quote
02-02-20, 07:40 PM   #2
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,237
https://wow.gamepedia.com/API_C_Timer.After
  Reply With Quote
02-03-20, 12:25 AM   #3
Nodos7
A Murloc Raider
 
Nodos7's Avatar
Join Date: Feb 2020
Posts: 4
Originally Posted by myrroddin View Post
Could you please add the example of code? Will it work in WoW Classic?
  Reply With Quote
02-03-20, 07:00 AM   #4
Xruptor
A Flamescale Wyrmkin
 
Xruptor's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2005
Posts: 133
something like this

Originally Posted by Nodos7 View Post
Could you please add the example of code? Will it work in WoW Classic?
There are several ways of using this function.

C_Timer.After(duration, callback)
duration is in seconds

Code:
C_Timer.After(1, function () SendChatMessage("I need help!") end)
C_Timer.After(2, function () SendChatMessage("Somebody, help!") end)
C_Timer.After(3, function () SendChatMessage("Too late I'm dead!") end)
or

Code:
local function doSomething()
   SendChatMessage("The world says, hello")
end

C_Timer.After(1, doSomething)
__________________
Click HERE for the ultimate idiot test.

if (sizeof(sadness) > sizeof(happiness)) { initDepression(); }

Last edited by Xruptor : 02-03-20 at 07:05 AM.
  Reply With Quote
02-03-20, 09:59 AM   #5
Nodos7
A Murloc Raider
 
Nodos7's Avatar
Join Date: Feb 2020
Posts: 4
Thank you! But i can't make this code working... It causes interface error and only display SendChatMessage message, not the C_Timer.After one...
  Reply With Quote
02-03-20, 01:45 PM   #6
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
What is your code now?
__________________
"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-03-20, 05:34 PM   #7
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,857
Requires a hardware event for certain channels now.
https://wow.gamepedia.com/API_SendChatMessage
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
02-04-20, 11:02 AM   #8
Nodos7
A Murloc Raider
 
Nodos7's Avatar
Join Date: Feb 2020
Posts: 4
Originally Posted by Seerah View Post
What is your code now?
I tried a lot variations, but they all are not worked. Sorry, i'm really noob at addons.

This code not working:
Code:
function ButtonHelp_OnClick()
    SendChatMessage("Help me!");
    C_Timer.After(3, function () SendChatMessage("Somebody, help!") end);
end
XML code:
Code:
<Button name="ButtonHelp" inherits="UIPanelButtonTemplate" text="Help Button">
	<Size>
	<AbsDimension x="50" y="23" />
	</Size>
		<Anchors>
			<Anchor point="TOPLEFT">
				<Offset x="300" y="0" />
			</Anchor>
		</Anchors>
			<Scripts>
				<OnClick>
					ButtonHelp_OnClick();
				</OnClick>
			</Scripts>
</Button>
I just want to run this macro as addon and make special button for it:
Code:
/say Help me!
/in 3 /say I need help!
  Reply With Quote
02-04-20, 01:46 PM   #9
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,857
If you can't do it as a macro because the hardware event is required for the second /say or the /in is seemingly being swallowed, you won't be able to do it as an addon.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 02-04-20 at 01:58 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Delayed message in chat

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