WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Classic - AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=179)
-   -   What's the simplest way to show a message on screen? (https://www.wowinterface.com/forums/showthread.php?t=57503)

tirafesi 09-16-19 08:47 AM

What's the simplest way to show a message on screen?
 
What's the simplest way to show a message on the screen? (outside of printing to the chat)

Something that I can show / hide whenever.

SDPhantom 09-16-19 02:49 PM

Depends on what you're doing with the text. Essentially, text on screen are FontString objects.

tirafesi 09-16-19 03:46 PM

Quote:

Originally Posted by SDPhantom (Post 333802)
Depends on what you're doing with the text. Essentially, text on screen are FontString objects.

Yeah, that's how I did it. But I was wondering if there was a more compact way of doing this without having to write 8 lines of code just to show one sentence ;-;

Code:

local msgFrame = CreateFrame("FRAME", nil, UIParent)
msgFrame:SetWidth(1)
msgFrame:SetHeight(1)
msgFrame:SetPoint("CENTER")
msgFrame:SetFrameStrata("TOOLTIP")
msgFrame.text = msgFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
msgFrame.text:SetPoint("CENTER")
msgFrame.text:SetText("Hello World")


Vrul 09-16-19 05:17 PM

Quote:

Originally Posted by tirafesi (Post 333805)
Yeah, that's how I did it. But I was wondering if there was a more compact way of doing this without having to write 8 lines of code just to show one sentence ;-;

Code:

local msgFrame = CreateFrame("FRAME", nil, UIParent)
msgFrame:SetWidth(1)
msgFrame:SetHeight(1)
msgFrame:SetPoint("CENTER")
msgFrame:SetFrameStrata("TOOLTIP")
msgFrame.text = msgFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
msgFrame.text:SetPoint("CENTER")
msgFrame.text:SetText("Hello World")


If you just want to quickly display some info you could use:
Code:

message("Hello World")
or you could remove creating a separate frame and just create a FontString from UIParent:
Code:

local text = UIParent:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
text:SetPoint("CENTER")
text:SetText("Hello World")


Xrystal 09-16-19 08:48 PM

D'oh.. it didn't even occur to me that I can make my own message box rofl

A frame with a border, and YES/NO/OK buttons as needed and a text box or two ( title, content ) and turn it into a template to use as needed.

tirafesi 09-17-19 04:39 AM

Oh, I can create the FontString directly from UIParent? Perfect! Exactly what I was looking for :D

Seerah 09-17-19 11:13 AM

If you just want text to appear on screen like an in-game message/warning would (out of range, etc.), then use the message() function.

(If that's even still in the client... It was deprecated long ago. If that doesn't work, then use UIErrorsFrame:AddMessage("text") - https://wow.gamepedia.com/API_MessageFrame_AddMessage)

If you want to control when it disappears off-screen, then create your own fontstring and show it or change the text as needed.


All times are GMT -6. The time now is 03:06 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI