New to Lua, and making AddOns. Need Help.
I'm trying to create a simple Death Dice (More so known as Death Rolling) addon, but loading up WoW Classic and testing it with my brother I get the /help error stating it's an invalid/incorrect command. I do see the AddOn in the AddOns tab, I made sure it's the correct "interface" number, and in the .toc file the .lua name matches the .lua file name exactly. Any help would be amazing, please and thank you ♥ Here is the code:
StaticPopupDialogs["DEATHDICE_CONFIRM"] = { text = "", button1 = "YES", button2 = "NO", OnAccept = function(self, data) StartGame(data.player, data.target, data.amount, data.unit) SendMessage("You start a Death Dice game with " .. data.target .. "! Type '/roll' to make your first roll.") end, OnCancel = function(self) SendMessage("You declined the Death Dice game.") end, timeout = 0, whileDead = true, hideOnEscape = true, preferredIndex = 3, } -- Update the SlashCmdList.DEATHDICE function to handle initiating and declining a match function SlashCmdList.DEATHDICE(msg) if isGameInProgress then SendMessage("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 SendMessage("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 SendMessage("Usage: /deathdice <amount> <unit> (e.g., /deathdice 100 gold)") 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 -- Update the StartGame function to accept the initiating player's name and the target's name local function StartGame(player, target, amount, unit) SendMessage("Death Dice game started! " .. player .. " vs " .. target .. ".") SendMessage("Bet amount: " .. amount .. " " .. unit .. ".") isGameInProgress = true currentPlayer = player betAmount = ConvertToCopper(amount, unit) end Again, to reiterate the title, this is my first addon, and honestly my first lua code. So if I did anything incorrect please help the best you can, I'm still not fully savvy with the lingo if you will lol. I did try a lua compiler on some site, but I get a nil error about the StaticPopupDialog not being implemented or something along those lines. I know that shouldn't be an issue within WoW since it's built into their 'system'. |
If you haven't already, to help with debugging in-game, install both
BugGrabber and BugSack As to the code, SendMessage isn't a lua or WoW API function, except as a method of the C_Club system. Maybe it's a custom function in another addon? To send text directly to the chatframe you can replace the SendMessage(...) lines with print(...) |
Quote:
When I tested this earlier btw, the window for yes and no buttons popped up, but they weren't clickable? |
You did not set an actual command to use. The slash system needs a string that is your command, and when used, then calls the matching SlashCmdList entry.
Lua Code:
You can make any number of different commands that call the same function, as long as the text between SLASH_ and the number is exactly the same as the entry in SlashCmdList, case sensitive. You only need just the number 1 line if you only want one command. |
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? |
Quote:
|
Quote:
-- 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" |
I can't see how. StartGame is completely missing from the code posted ;).
The ConvertToCopper function is also missing (and not an API function) so that will cause an error. In future, place your code inside code tags (either the # or Lua buttons above the edit box). Lua Code:
|
Noted! I will definitely keep that in mind :D Thank you for the help, I truly appreciate it lol. I'm in fact a noobie lol. I did away with the ConvertToCopper, added the StartGame that I SOMEHOW deleted, it's mostly working (the error comments at least lol) but I go to do /deathdice 5 copper and it won't even let me click enter, just stays in the chat bar while targeting my friend to test. Though, when not targeting my friend it enters, but shows the "You must target a friendly player to start a Death Dice game." error message. I'm missing stuff, or maybe something is in the wrong place is all I can think :confused:, also I downloaded the BugGrabber and BugSack, since I forgot to earlier. Will definitely install them and test with them! Here's what I have updated lol
Lua Code:
|
If you get and error, execution of the current process stops there. If you click Enter and get an error in the running code then the StaticPopupDialogs code won't get to the part where it closes the popup frame.
Installing the debugging addons will let you know when you've hit an error. |
Have you considered checking if there are any errors in your code that might be preventing the execution of certain functions, especially when clicking Enter in the chat, and have you installed the debugging addons for better visibility?
|
Quote:
|
If you've installed the debugging addons and get an error the BugSack icon will turn from green to red (that and you should hear a warning sound...get used to that ;)).
Clicking the BugSack icon will open the error frame with the last? error text displayed. You can select/copy/paste the error text here along with your code and maybe we can help you figure out why you got the error. If you have several errors BugSack has Previous/Next buttons for moving through them and a button to limit the view to just the current errors. |
All times are GMT -6. The time now is 01:02 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI