WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Static PopUp text help (https://www.wowinterface.com/forums/showthread.php?t=52081)

Kraiven 03-12-15 06:09 PM

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.

Duugu 03-12-15 06:48 PM

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

Kraiven 03-12-15 07:22 PM

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.

Duugu 03-12-15 07:49 PM

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?

Phanx 03-13-15 05:00 AM

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.

Kraiven 03-13-15 07:05 AM

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.

Seerah 03-14-15 12:28 PM

http://wow.gamepedia.com/Creating_si...ext_parameters


All times are GMT -6. The time now is 05:41 AM.

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