Disable event on click?
Hi,
I have a quick question to ask. I am not use to not using KgPanels and I am just trying to make a small addon instead with a .lua file. This should be very simple. How do I make the Shadowed Unit Frames addon recognisable in my script since it just comes up as nil: Code:
if ShadowUF.db:GetCurrentProfile() == "ProfileName" then attempt to index global 'ShadowUF' (a nil value) Thank you! :D _ |
I don't see exactly how your topic title relates to what you're asking.
Anyhow. What's probably happening is that your addon loads after Shadowed Unit Frames. You need to delay all code with references to ShadowUF until it actually exists. You can do this by registering the ADDON_LOADED event and letting your code run only once the addon parameter is what you need. For example; Code:
local f = CreateFrame("Frame") |
Quote:
Thank you so much, I will try that now! |
Ok my finished code is there:
Code:
local f = CreateFrame("Frame") "BTL:Show() TL:Hide()" part never reaches as both of the frames are showing for some reason. I had to also change "ShadowedUnitFrames" to "ShadowUF" because for some reason it came up with a lua error saying that "db" is a nil value but with that instead I do not get any errors. Not sure what that's about. I will keep up the experimenting. |
It's probably being shown after you hide it.
|
Quote:
Hey :) Are BTL and TL variables which point to the frames somewhere else in your script? I'm just asking because if you've posted your full script, there's no way that your code is going to know what BTL and TL is. I'd also consider registering to the "PLAYER_LOGIN" event too, just in-case your addon loads after ShadowedUF. If it does load after ShadowedUF, "ADDON_LOADED" will not catch the event (because it fired before your addon existed). Lua Code:
Right enough, an easier way would be to simply add ShadowUF as a dependency in your TOC file if your code is pointless without ShadowUF (or an optional dependency if you'd still like your code to run even if ShadowUF has been disabled). The game will then try to ensure that ShadowUF is loaded prior to your addon which will remove some of the guesswork. Using print() like the example above is a pretty handy way of working out where you're going wrong although I suspect that in the above example, if ShadowUF is loaded early on in the addon loading process, it might not print to chat even if your func does reach that line of code... but it's worth trying. Aanson |
Quote:
I can most the entire script the project I'm working on if that helps. Basically I want to expand on my Setup addon so that you click the install button and it uses a reflux command to change everything to "MayronUI" profile and reloads the UI. After that I need a script that if any of the addons are set to "MayronUI" profile then it hides the Setup box art with the install buttons etc and displays this new box: Here you can enable some "bonus features" which do the following things in the annotation on the image above. I wanted to make this because its complicated for users to have to follow long steps of moving hte chat box with other addons after installing the UI so I wanted to make it easier. So far so good but the main issue is that the script does not recognise the addons loading and I really do not know what to do about it. Your welcome to see what I've done so far and if I have done other things wrong and the work is too much then I understand. The Addon file is here: http://www.mediafire.com/?awc6e990yvz227y |
I didn't look at your code, but I'd use the PLAYER_LOGIN event -- so that all non-LoD addons are loaded by the time it fires and, assuming they're using AceAddon's OnInitialize, have loaded and set up their profiles -- in conjunction with a saved variable for your addon; in this (fairly loose) example I've used the saved variable name MUI_INSTALLED.
Code:
local addons = { |
wow I didn't expect all of that but thanks so much. It may take me a long time to implement it with my code as I don't know a lot about lua but hopefully your notes will help me out. I really hope I can get this working! Thank you Phanx :)
|
Ok I have now implemented your code and I am not getting any lua errors but I still haven to managed to get it to work. I have not changed the buttons into checkbuttons yet as I am not sure how to do that but most importantly because when I log on, the UIParent is still showing, the "block" frame I am using for the slight transparent black background frame is missing and both the "TL" and "BTL" frames which are the setup box and bonus box is showing together and I am unsure what the issue is. So I have been trying to get that right before worrying about the checkbuttons. I thought it would have something to do with the fact that MUI_INSTALLED has not been told what it is. That part confused me but I can either paste the entire code here or you can download the MayronSetup addon with the lua file:
http://www.mediafire.com/?4mw4u7s408s6yib Thank you for the help I really appreciate it and will of course give you credit for your work if we get it working ^^ |
MUI_INSTALLED should be defined as a saved variable in the TOC file for your MayronUI addon. It doesn't need to be defined in the Lua file because it's never used before your addon's ADDON_LOADED event, when the game automatically defines it as either its saved value, or as nil if you haven't loaded the addon before or haven't set the variable to anything else before.
Code:
## SavedVariables: MUI_INSTALLED Also #2, you don't need to give every object a global name -- in fact, most objects don't need one -- and global names should be descriptive enough that they both (a) identify which addon they belong to, and (b) be extremely unlikely to conflict with anything else, so "BBL" and "ExitB" aren't good global names. In your case, I don't see anything in MayronSetup.lua that actually needs a global name, so I'd suggest passing nil for that part of the CreateFrame call. Edit #3: There are some typos in your text, eg "Shadowed Unite Frames" with an extra "e", and "reframe from changing" instead of "refrain from cchanging". Edit #4: It is against Blizzard's addon policy to solicit donations in-game, so you should remove the part where you ask for donations and describe how to send donations. It's okay to include that on the download page or in a README file in your addon's folder, just not in-game. |
Thank you for that very interesting info and for taking the time to look at my .lua file. I was actually expecting there to be much worse errors in it since its the first big lua project I've ever worked on. I've definitely learnt a lot and will correct those errors.
Also in your "frame:SetScript("OnEvent", function(self, event, ...)" part of the script, the "frame" comes up as a nil variable when I run it in wow. Is that because I am meant to rename the "frame" to any other frame that preferably is not already using an OnEvent script and which is always showing such as the "block" frame that does not disappear until the very end? Either that or some how defining "frame" as an actual variable then. Edit: It is also saying that this line: Code:
if _G[addon].db:GetCurrentProfile() == "MayronUI" then |
Quote:
Quote:
One way to solve it: lua Code:
|
I've fixed everything you recommended Phanx except I have not altered the donations thing just yet as I will do that when I have the actual addon up and running because I thought it would be easier that way. All of the frames with horrible names on them such as "BTL" have been renamed to things such as "BonusTopLeft" to make it easier.
And thank you ravagernl for that but I cannot seem to get that to work. Having great difficulty. I have uploaded the latest updated .lua file so you can have a look at where I went wrong if you like. I've made a lot of the code much easier to read hopefully. Thank you so much! http://www.mediafire.com/?tlg83dq8sy3a854 |
I'm fairly certain that the global name for kgPanels is "kgPanels" with a lowercase "k", not KgPanels" with an uppercase "K".
Also: You should parent your "top level" frames to UIParent, not WorldFrame, so that they respect the user's UI scaling settings and are correctly hidden when the UI should be hidden. Most of your sub-frames look like they should actually just be Texture objects, not Frame objects, and for Button objects you should use SetNormalTexture instead of SetBackdrop. Font strings in WoW are limited to around 32px in height. SetFont won't complain if you give it larger values, but WoW also won't actually render the fontstring with a larger height. Once you get over 28-36 (depending on the font file you're using) the rendered fontstring won't actually get any bigger. Font strings default to white and center-aligned, so there's no need to explicitly set those properties. I'd suggest keeping related sections of code together -- eg. create a button, add a font string, set scripts, create the next button, etc. instead of create all buttons, then create all font strings, then set all scripts. It's also a good idea to define objects in roughly the order they'll be displayed, so you'd want to define your title bar, then your section headings, then your section descriptions, then your exit button last. Anyway, I ended up rewriting the whole thing: http://pastebin.com/3TfYtMzY Works as far as I can tell without having any of the relevant addons installed for it to do profile stuff with. Edit: For future reference, just putting the relevant file on pastebin.com or paste.wowace.com is faster than re-uploading the whole ZIP with 6 MB of texture files. ;) |
You can switch it back to WorldFrame... but if you do, then add this at the top of the OnShow function:
Code:
UIParent:Hide() Code:
MayronSetupFrame:SetScript("OnHide", function(self) |
I don't think you can hide/show UIParent programmatically without tainting.
|
Everything is working great except for one small issue.
When I use the addon to install the UI on one character, the SavedVariable file says "MUI_INSTALLED = true" which is set for the entire account by the looks of it and so I cannot then use the addon again on another character to set the UI up for a second. Is there a way around this? Thank you :D Also I can live without this but thought I might as well ask. When The UIParent:Hide() function fires with your event you posted I noticed that when I press the Escape key, the UIParent shows up again which I didn't think happened before but never really tested it. That to me seemed a bit odd. Is there a way to stop that from happening? |
Quote:
to: "## SavedVariablesPerCharacter: MUI_INSTALLED" in the toc file. It's that easy. Quote:
Another way to do this is to use an overlay texture or frame instead of hiding the entire UIParent: lua Code:
This doesn't hide the UI, but it does give the user the attention that UI setup is needed. |
All times are GMT -6. The time now is 04:11 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI