WoWInterface - View Single Post - Help with SetScript
View Single Post
08-15-16, 02:14 AM   #3
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Apart from that, there is an actual syntax error in your code. This isn't valid Lua:

lua Code:
  1. if RepairProfession == "Engineering" then
  2.                 CastSpellByName("Field Repair Bot 74A") or CastSpellByName("Field Repair Bot 110G") or CastSpellByName("MOLL-E") or CastSpellByName("Scrapbot") or CastSpellByName("Jeeves")
  3.             else

That second line would only be valid if it started with a variable assignment ("local x =") or a keyword like "if" or "return".

I assume your intention was "try each of these and cast the first one that's available". Not only is (as Vlad already said) that not allowed -- you can't call CastSpellByName in an addon for any actual spell (only for professions, but there are better ways to open the tradeskill UI that you should use instead of that) -- but even if it was allowed, you couldn't do it that way. You'd need to do something like this instead:

lua Code:
  1. if RepairProfession == "Engineering" then
  2.         if GetItemCount("Field Repair Bot 74A") > 0 and GetItemCooldown(123) == 0 then
  3.             CastSpellByName("Field Repair Bot 74A")
  4.         elseif GetItemCount("Field Repair Bot 110G") > 0 and GetItemCooldown(456) == 0 then
  5.             CastSpellByName("Field Repair Bot 110G")
  6.         elseif GetItemCount("MOLL-E") > 0 and GetItemCooldown(789) == 0 then
  7.             CastSpellByName("MOLL-E")
  8.         elseif GetItemCount("Scrapbot") > 0 and GetItemCooldown(852) == 0 then
  9.             CastSpellByName("Scrapbot")
  10.         elseif GetItemCount("Jeeves") > 0 and GetItemCooldown(159) == 0 then
  11.             CastSpellByName("Jeeves")
  12.         end
  13.     else

or you could make a table instead:

lua Code:
  1. local EngineeringRepairItems = {
  2.     -- note these are random numbers,
  3.     -- not the actual item IDs.
  4.     123,
  5.     456,
  6.     789,
  7.     852,
  8.     159
  9. }

and then do:

lua Code:
  1. if RepairProfession == "Engineering" then
  2.         for _, id in next, EngineeringRepairItems do
  3.             if GetItemCount(id) > 0 and GetItemCooldown(id) == 0 then
  4.                 CastSpellByName(GetItemInfo(id))
  5.                 break
  6.             end
  7.         end
  8.     else

To work around the fact that you can't call CastSpellByName directly, your best bet is probably:

- Create an invisible secure action button
- When the user mouses over your data panel button, check for combat lockdown
- If you're not in combat, show the action button and reposition it to cover your data panel button
- When the user mouses away from the action button, or the user enters combat, hide the secure button and ClearAllPoints it (if you leave it anchored to an insecure button it will break)
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