WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Classic - AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=179)
-   -   Protected function help (https://www.wowinterface.com/forums/showthread.php?t=59760)

soulreeperxiii 01-13-24 10:25 PM

Protected function help
 
I cant figure out how to get this working. Blizzard says its a Protected Function. Is there any way to get this to run?

Code:

FrameButton:SetScript("OnClick", function()
        local index = GetCraftSelectionIndex()
        DoCraft(index)
end)


Xrystal 01-14-24 08:51 AM

It depends on what you were hoping to achieve.
What part of the system you are working with.
Whether you were in combat at the time the error happened
And whether you set up your custom frame button to work in the secured environment ( if it's needed ).

For example:
This example for the OnClick command ( https://warcraft.wiki.gg/wiki/UIHANDLER_OnClick ) doesn't mention the need for a secured environment, so it should not error out like that.

So, depending on what the other 2 functions relate to and access could point to the reason why you are having this problem. Maybe seeing what those other functions do will help identify the cause.

soulreeperxiii 01-15-24 05:48 AM

I am working with Blizzard_CraftUI.lua and Blizzard_CraftUI.xml
Neither of those two functions are documented, I am inferring what they do by looking at Blizzards code.
Its the DoCraft() function that fires the Protected event.

I think its a secure environment that I need? But I cant figure out how to do it. Here's what I've come up with so far:

Code:

local button = CreateFrame("Button", "FrameButton", UIParent, "SecureHandlerBaseTemplate")
button:SetScript("OnClick", function()
        local index = GetCraftSelectionIndex()
        DoCraft(index)
end)


Xrystal 01-15-24 06:37 AM

Ah gotcha.

Not played with that (DoCraft) functionality myself but ..

https://warcraft.wiki.gg/wiki/Secure...rClickTemplate

Creating a button from a SecureHandlerClickTemplate would be a starting point as that would let you use a button to do something that is part of the secure frame system. This gives you a brief example but bear in mind that you have to pass information into the secure system for it to be accessible. The example creates 2 frame variables to use the frames.

Now, whether, protected functions work this route I don't know.

Looking at nUI there is a secure click button in use there with a somewhat simple set up. So I will grab out it's code as an example. I'm not sure how successful this will be for your task, as the button nUI uses just activates the visibility of another frame, so just comment out your code or make a copy of the file in case you need to go back to it.


Lua Code:
  1. local mysecurebutton       = CreateFrame( "Button", "MySecureButtonName", UIParent, "UIPanelButtonTemplate,SecureHandlerClickTemplate" )
  2. mysecurebutton:SetPoint("CENTER")
  3. mysecurebutton:SetSize(100, 40)
  4. mysecurebutton:SetText("DoCraft")
  5.  
  6. mysecurebutton:SetAttribute(
  7.     "_onclick",
  8.     [[
  9.         local index = self:GetAttribute( "craftselectionindex" )
  10.         DoCraft(index)
  11.     ]]
  12. )
  13.  
  14.  
  15. -- Somewhere in the rest of your code make sure this line is called before clicking the button
  16. mysecurebutton:SetAttribute( "craftselectionindex", GetCraftSelectionIndex() )

For reference this is a page of info regarding the secure handlers
https://warcraft.wiki.gg/wiki/SecureHandlers

soulreeperxiii 01-15-24 11:11 AM

Thanks for the help Xrystal, i appreciate it. I plugged your example into my code and managed to get it to run. This was exactly what I needed. However, I think I have a new problem now.

This works perfectly and outputs the expected index value in the Print function.
Lua Code:
  1. mysecurebutton:SetAttribute(
  2.     "_onclick",
  3.     [[
  4.         local index = self:GetAttribute( "craftselectionindex" )
  5.         print(index)
  6.     ]]
  7. )

This does absoluty nothing at all, no error when ran but also seems to not even perform the function.
Lua Code:
  1. mysecurebutton:SetAttribute(
  2.     "_onclick",
  3.     [[
  4.         local index = self:GetAttribute( "craftselectionindex" )
  5.         DoCraft(index)
  6.     ]]
  7. )

My guess is there is something more the defaut UI is doing for DoCraft() to function that I am not doing.
The Proteced message is not popping up but neither does it do anything.
Is there some type of logging mechanic I can use to see whats going on under the hood?

Kanegasi 01-15-24 01:57 PM

There are two basic types of protections: hardware and full.

If it's a hardware protection, the function can only be called with a mouse click or a key press.

If it's a full protection, no custom code can use it at all.

If you're trying to get your code to autocraft it and it's giving you a protected error, try making a secure button and either click it or assign it to a key to continue the craft.

Xrystal 01-15-24 02:45 PM

As I suspected, the protected side of the DoCraft function might not be allowed by addons at all.

Debugging:
I don't think there will be much you can do if it isn't erroring out noisily. I suspect because it is being called in a secure environment it is just silently failing because it isn't a Blizzard addon calling it. However, if you don't have Bugsack or Buggrabber installed, you might want to, and see if they see something.


Protected functions with no accessible code:
There is no DoCraft function in the accessible Blizzard code that I can see which could explain why there is no info on it in the wow api code. It's probably one of their behind the scenes code that is just called by valid callers.

It is only used directly in the xml file on the Crafting Button that you click in their UI.
https://github.com/Gethe/wow-ui-sour...rd_CraftUI.xml

Looking for that button control in the lua file to see if they do anything else with it and apart from enabling and disabling I also noticed this line of code. However, like DoCraft(), this GetCraftButtonToken() function doesn't exist anywhere else.

Lua Code:
  1. -- Set the action button text
  2.     CraftCreateButton:SetText(getglobal(GetCraftButtonToken()));
https://github.com/Gethe/wow-ui-sour...raftUI.lua#L99


Did you try making sure the Blizzard addon is loaded to see if it is needed to have access to these functions? :
If you haven't already, you could try making sure that the Blizzard_CraftUI addon is loaded before using it's functionality.

soulreeperxiii 01-17-24 05:22 PM

Thank you for all your help. At the very least, I now have a much better understanding of secure templates and handlers.
I am going to give up on getting this function to work. I know it used to work in original vanilla wow (BeastTraining) with no special secure templates, but no longer. It might be that it can only be called from a bliz addon, and its just hardwired that way, never changing. Who knows.

Anyway, thanks again and I did learn from this :D

Xrystal 01-17-24 08:41 PM

Quote:

Originally Posted by soulreeperxiii (Post 343201)
Thank you for all your help. At the very least, I now have a much better understanding of secure templates and handlers.
I am going to give up on getting this function to work. I know it used to work in original vanilla wow (BeastTraining) with no special secure templates, but no longer. It might be that it can only be called from a bliz addon, and its just hardwired that way, never changing. Who knows.

Anyway, thanks again and I did learn from this :D

Oh yeah, that was a long time ago. They made some heft secure/protected changes after then.

Working on nUI has helped me understand them somewhat - but I still get regular errors that I haven't figured out yet, any attempt at fixing where I think the problem is, just compounds the problem more. Like BeastTraining nUI has been around for a long time and likely has quite a lot of code working the way it shouldn't. I keep saying it, but maybe next expansion ( 20 years anniversary edition rewrite rofl ) but I said this 10 years ago and every expansion since and it just never happens rofl.


All times are GMT -6. The time now is 07:03 AM.

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