Script converting to ADDON [HELP] Request

Hi there,

I am trying to convert a simple script into an addon so i dont have to run it every log in.

I’ve had previous success making scripts into addons before but for some reason this code wont run unless i manually run it in game.

Heres the code in my .lua file:

PlayerPrestigeBadge:SetAlpha(0)
PlayerPrestigePortrait:SetAlpha(0)
TargetFrameTextureFramePrestigeBadge:SetAlpha(0)
TargetFrameTextureFramePrestigePortrait:SetAlpha(0)
FocusFrameTextureFramePrestigeBadge:SetAlpha(0)
FocusFrameTextureFramePrestigePortrait:SetAlpha(0)

Now if i type “/run PlayerPrestigeBadge:SetAlpha(0)” in-game the desired effect takes place. I made two macros with 3 lines each of the above txt and add “/run” before each line and run them each time i log in and it all works but when i take the code and add it to a “myaddon.lua” and take off the “/run” before each line it simply doesn’t work. It shouldnt need “/run” prefix in the .lua to my understanding nor does it work if i do add /run prefix each line in the .lua.

So what am i doing wrong here?

tl:dr

/run PlayerPrestigeBadge:SetAlpha(0) works ingame but PlayerPrestigeBadge:SetAlpha(0)
doesnt work in .lua and i dont know why

It’s a race condition issue. Your addon is firing the command before the frames you’re trying to manipulate have been loaded.

I don’t have a solution for you but those who are more Lua minded will be able to help.

typically you set a dependency in your toc file for the blizzard addon (eg bank, guild bank, etc) but this seems to be the base UI so you probably need to wait for an event like PLAYER_ENTERING_WORLD to ensure the UI is loaded.

failing that you could create your own frame and have a loop in its OnUpdate function to check if both those frames exist, once the do then your code runs and hides the frame (which stops the OnUpdate from triggering.

this is ugly but it should work;

local frame = CreateFrame( "Frame" )

frame:SetScript( "OnUpdate",
	function( self, elapsed )
		
		self.timer = ( self.timer or 0 ) + elapsed
		
		if self.timer > 5 then
			
			self.timer = nil
			
			if PlayerPrestigeBadge and PlayerPrestigePortrait and TargetFrameTextureFramePrestigeBadge and TargetFrameTextureFramePrestigePortrait and FocusFrameTextureFramePrestigeBadge and FocusFrameTextureFramePrestigePortrait then
				PlayerPrestigeBadge:SetAlpha(0)
				PlayerPrestigePortrait:SetAlpha(0)
				TargetFrameTextureFramePrestigeBadge:SetAlpha(0)
				TargetFrameTextureFramePrestigePortrait:SetAlpha(0)
				FocusFrameTextureFramePrestigeBadge:SetAlpha(0)
				FocusFrameTextureFramePrestigePortrait:SetAlpha(0)
				self:Hide( )
			end
			
		end
		
	end
)

frame:Show( )

Those frames are part of FrameXML so they should be loaded before 3rd party addons.

There may be something wrong with the folder/toc names of your addon (does it show up under the Addons button?).

Take what’s posted in the OP and paste it into the website addon.bool.no to create a complete addon to download/install.

thanks so much for your work this far.

i copy pasted your code into my .lua but it doesnt seem to provide any result for me. I’m just wondering if u tested this on your side first? Just wondering if its a problem on my end. Btw yes my addon shows up on my list so it is running

Shouldnt be a problem with my addon files i copy pasted a different working addon i made a while back and changed the name then pasted my code over the old addon. it shows up in my list under its new name and everything.

In your addon add
FyTest = "FY Test"

Log into the game and

/run print(FyTest)

If it doesn’t print FY Test to your chat frame then your addon isn’t loading properly.

I tested the code, it stops the frames from displaying unless you set the alpha back to 1 (and add a texture if you don’t have a rating)

ok so /run print(FyTest) ingame is returning “nil” in the chat frame so something is wrong with my addon.

heres my folder structure in my interface > addons i made “HidePrestigeIcons” folder.

Inside that folder i made 2 files:

hideprestigeicons.toc

Interface: 90000

Title: Hide Prestige Icons

scriptcontainerone.lua

and also:

scriptcontainerone.lua

FyTest = “FY Test”

local frame = CreateFrame( “Frame” )

frame:SetScript( “OnUpdate”,
function( self, elapsed )

	self.timer = ( self.timer or 0 ) + elapsed
	
	if self.timer > 5 then
		
		self.timer = nil
		
		if PlayerPrestigeBadge and PlayerPrestigePortrait and TargetFrameTextureFramePrestigeBadge and TargetFrameTextureFramePrestigePortrait and FocusFrameTextureFramePrestigeBadge and FocusFrameTextureFramePrestigePortrait then
			PlayerPrestigeBadge:SetAlpha(0)
			PlayerPrestigePortrait:SetAlpha(0)
			TargetFrameTextureFramePrestigeBadge:SetAlpha(0)
			TargetFrameTextureFramePrestigePortrait:SetAlpha(0)
			FocusFrameTextureFramePrestigeBadge:SetAlpha(0)
			FocusFrameTextureFramePrestigePortrait:SetAlpha(0)
			self:Hide( )
		end
		
	end
	
end

)

frame:Show( )

My addon shows as “Hide Prestige Icons” ingame on my addons list.

I disabled MoveAnything addon thinking it might be messing with this as i tried to find its cvars with that addon but they arent present how ever relaunching with this addon off doesnt effect my result (or lack of)

Any suggestions at this point?

Sorry i dont know how to format these poosts is auto making it all weird with the scroll window and stuff i just dont know how to not make it liek that

nope, its copy/pasted/updated from my own mod. basically dry coded. it should work as notepad++ didnt seem to show any nesting errors but thats always possible.

install bug grabber and bug sack, those should capture any errors and you can work out from those what the issue is

three backtick ``` characters on their own line above and below the section you want as code;

three on the line above
code here
three on the line below

or use a single one around text to get this inline effect

Go to the website addon.bool.no
In the Title line change MyFirstAddon to HidePrestigeIcons.

In the Code box copy/paste

PlayerPrestigeBadge:SetAlpha(0)
PlayerPrestigePortrait:SetAlpha(0)
TargetFrameTextureFramePrestigeBadge:SetAlpha(0)
TargetFrameTextureFramePrestigePortrait:SetAlpha(0)
FocusFrameTextureFramePrestigeBadge:SetAlpha(0)
FocusFrameTextureFramePrestigePortrait:SetAlpha(0)

Click Download.

Move/Rename your current addon and replace with the newly downloaded one.

Edit for: Incorrect website spelling .

1 Like

alright so it works after just sucking it up and using the website, im sorry for wasting everyones time. I assume the spaces i had in the “title: Hide Prestige Icons” in the .toc was breaking it? It’s basically the only difference i could see.

Thanks again to you and Arkayenro for all your help and hard work.

1 Like