Quantcast Static PopUp text help - WoWInterface
Thread Tools Display Modes
03-12-15, 06:09 PM   #1
Kraiven
A Deviate Faerie Dragon
 
Kraiven's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2015
Posts: 10
Static PopUp text help

I'm using a static popup method to display a warning message to users about being in the wrong spec. I'd like to add some returned values from the api into the 'text =""' field, but every way I have tried doesn't seem to work. I know if I use message() to print I can do it, but I was wondering if there was a way to express this using the static popup dialog. I have searched high and low and can't find any examples or answers as to how or why I can't.

Example code: the yellow text is where I would like to put some values in, but can I only use text? Is there a better way to achieve this?
Code:
StaticPopupDialogs["WRONG_SPEC_WARNING"] = {
	text = "Role: " .. roleReturnValueHere, "SpecRole:" specReturnValueHere,
	button1 = "Change Talent Spec",
	button2 = "Not Right Now",
	OnAccept = function(self)
		local inLockdown = InCombatLockdown() -- Check if in combat 
		if inLockdown then
			message("|cffff0000WARNING!|r \n \n |cffffff00In combat and unable to switch specs at this time. \n Try again when combat has ended.|r")
		else	
			SetActiveSpecGroup(GetActiveSpecGroup()%2+1) -- Switches Talent Spec
		end
	end,
	showAlert = true,  -- Alert Icon in PopUp
	timeout = 0,
	whileDead = false,
	hideOnEscape = true,
	preferredIndex = 3,
}
Obviously I would have the arguments called in locals. Thank you for any advice! Always appreciated.
  Reply With Quote
03-12-15, 06:48 PM   #2
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
I would say it's
Lua Code:
  1. text = "Role: " .. roleReturnValueHere .. " SpecRole: " .. specReturnValueHere,

I have no idea what your version was meant to do.

You know the .. operator concats strings, right?
http://www.lua.org/manual/5.3/manual.html#3.4.6
  Reply With Quote
03-12-15, 07:22 PM   #3
Kraiven
A Deviate Faerie Dragon
 
Kraiven's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2015
Posts: 10
Sorry I'll try to explain it quickly. The popup window says basically

| "You're active role: (tank/damager/healer), You're assigned LFG role: (tank/damager/healer). |

I can't seem to get two values to print in the popup message. If I use more than 1 set of quotation marks, the popup does not display. I've used the concatenations like you suggested, even tried them before. I'm pretty much wondering if it's even possible to do within the popup "text" field.

I tried like this:
Code:
	text = "Active Role: " .. spec .. " Assigned LFG Role: " .. specName,
No popup is displayed.
  Reply With Quote
03-12-15, 07:49 PM   #4
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
I am pretty sure that this problem is not about string concatenation. What are the values of the variables?
What does print("Role: " .. roleReturnValueHere .. " SpecRole: " .. specReturnValueHere) show?

Could you please show your full code?
  Reply With Quote
03-13-15, 05:00 AM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
The problem has nothing to do with concatenation, even though you're doing that wrong in your example. The problem is that a static popup is only defined once, but the OP wants the text it displays to changable. Fortunately, there are several simple solutions available.

#1 - Your text can include up to 2 formatting tokens, and you can pass up to 2 values to StaticPopup_Show:

Code:
StaticPopupDialogs["WRONG_SPEC_WARNING"] = {
	text = "Your active role: %s|nYour assigned LFG role: %s",
	-- etc.
}

StaticPopup_Show("WRONG_SPEC_WARNING", roleReturnValueHere, specReturnValueHere)
#2 - Just change the text before you show the dialog:
Code:
StaticPopupDialogs["WRONG_SPEC_WARNING"] = {
	text = "Placeholder text",
	-- etc.
}

StaticPopupDialogs["WRONG_SPEC_WARNING"].text = "Your active role: " .. roleReturnValueHere .. "|nYour assigned LFG role: " .. specReturnValueHere
StaticPopup_Show("WRONG_SPEC_WARNING")
The first method is the "official" one, and is simpler, but you'd need to use the second one if you have more than 2 variables, or want to change the whole text, though you could work around that by just setting the text to "%s" and then passing in the entire text you wanted as the second argument to StaticPopup_Show.

Also make sure you have some kind of error display enabled. If your code is "not working" or "nothing happens" there's almost certainly a Lua error telling you exactly what's wrong on which line of code.
__________________
Author/maintainer of Grid, PhanxChat, oUF_Phanx, 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!
  Reply With Quote
03-13-15, 07:05 AM   #6
Kraiven
A Deviate Faerie Dragon
 
Kraiven's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2015
Posts: 10
Thank you guys again for the help. Phanx that worked exactly how I needed it. I was trying to find some help on how to use the "%s" format within a static popup. I only needed two options so the first one did it. I was missing this part...

Code:
local role = UnitGroupRolesAssigned("player"); -- Role selected or assigned in LFG 
local spec = GetSpecialization()
local specRole = GetSpecializationRole(spec)  -- Current Role Specialization
if role ~= specRole then
    StaticPopup_Show("WRONG_SPEC_WARNING", role, specRole)
Surprisingly I could not find any examples of these through the wow code or other addons.
  Reply With Quote
03-14-15, 12:28 PM   #7
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,719
http://wow.gamepedia.com/Creating_si...ext_parameters
__________________
"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

WoWInterface » Developer Discussions » Lua/XML Help » Static PopUp text help

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