View Single Post
02-15-24, 06:10 PM   #7
DennytXVII
A Murloc Raider
Join Date: Feb 2024
Posts: 6
Originally Posted by Fizzlemizz View Post
They work but the Yes will error on click because StartGame is declared as a local function and it appears in your code below the StaticPopupDialogs["DEATHDICE_CONFIRM"] declarations meaning it's not in scope (can't be seen).

Either move the function above the popup declaration (probably best) or remove the local declaration from StartGame making it global (in which case, StartGame is probably not a good name for it as all addons (inclucing the whole default game UI) share the same global space and Blizz. tends to use "common" names for their stuffs) so DeathDiceStartGame maybe?
I think I fixed this, but I'm not 100% just yet until I test it, here is the revised code I have currently, sorry for length:

-- Define the confirmation popup dialog
StaticPopupDialogs["DEATHDICE_CONFIRM"] = {
text = "Do you want to start a Death Dice game?",
button1 = "Yes",
button2 = "No",
OnAccept = function(self, data)
StartGame(data.player, data.target, data.amount, data.unit)
print("You start a Death Dice game with " .. data.target .. "! Type '/roll' to make your first roll.")
StaticPopup_Hide("DEATHDICE_CONFIRM") -- Close the confirmation popup
end,
OnCancel = function(self)
print("You declined the Death Dice game.")
StaticPopup_Hide("DEATHDICE_CONFIRM") -- Close the confirmation popup
end,
timeout = 0,
whileDead = true,
hideOnEscape = true,
preferredIndex = 3,
}

-- Define the SlashCmdList.DEATHDICE function to handle initiating and declining a match
function SlashCmdList.DEATHDICE(msg)
if isGameInProgress then
print("A Death Dice game is already in progress!")
return
end

local player = UnitName("player")
local targetName = UnitName("target")
local amount, unit = tonumber(msg:match("(%d+)")), msg:match("(%a+)")

if not targetName then
print("You must target a friendly player to start a Death Dice game.")
return
end

if not amount or not unit or (unit ~= "copper" and unit ~= "silver" and unit ~= "gold") then
print("Usage: /deathdice <amount> <unit> (e.g., /deathdice 5 copper)")
return
end

local confirmation = StaticPopup_Show("DEATHDICE_CONFIRM", "Do you want to start a Death Dice game with " .. targetName .. " for " .. amount .. " " .. unit .. "?")
if confirmation then
confirmation.data = { player = player, target = targetName, amount = amount, unit = unit }
end
end
SLASH_DEATHDICE1 = "/deathdice"
  Reply With Quote