Checking for files and [brackets]
Hello
2 little questions: - is there a way to check if a file is loaded. Some sort of isFile function - what's the difference between using myfile = [[myfile]] and myfile = "myfile" :confused: |
Quote:
Difference is first version uses the string verbatim. You can use [[Interface\AddOns\MyAddon\Sounds\my.mp3]] as opposed to "Interface\\AddOns\\MyAddon\\Sounds\\my.mp3" for the second. (had to escape '\') |
Quote:
|
Yea I put no in double-quotes because there's tricks you can do to "fake it".
But I got the OPs question to mean checking for a file that's not under your control. (ie a file of your own addon that might or might not be present but you have control over what it contains if it's actually there) And wowlua has no generic file io capabilities whatsoever so you cannot check for arbitrary files. |
Well, I'm kinda confused on what file your trying to test for.
If its a file within your addon folder, simply make sure it gets called before the one that needs it in the .toc (or .xml <Script />) if its a file from another addon, in your .toc add # Dependencies: OtherAddon and that addon (and its associated files) will be loaded first. also Code:
local bool, retVal1, retVal2, reValn = pcall(someFunc, param1, param2, paramn) |
Never felt the need myself, but this should work fine.
When an addon is loaded, each file is passed two arguments (accessed via "..."): The addon's name as WoW sees it, and a table. The table is specific to the addon and intended to be its namespace, allowing you to share variables and other info between files without polluting the global namespace (_G). Knowing that, we can use that namespace to get around the file-checking issue. Code:
-- Top of every file (change 'fileName' as needed) If you're working with libraries and such, you probably don't want to change their code. There are other, less invasive methods of checking for them. Edit: And yes, you can turn that into an on-demand function instead. Code:
local function isFile(file) |
well, what if her mod's name is "Ze best mod Eva"
if her addon is loaded last, wouldnt her onload only be called on functions after hers? |
Quote:
Quote:
Basically, that script without any modifications will have info available for every file contained within that addon specifically, which is honestly all that should be needed. If you're checking for another addon entirely, a simple IsAddOnLoaded('addonName') check can confirm that it's there. You can check for another addon's frames easily as long as they're named and in the global namespace, and if the addon uses global variables or makes its namespace available globally, those are also accessible. |
oh i wasnt saying Ze best mod ever because of spaces, but because it started with a "Z"
If the addons load in order, wouldn't her frame be unavailable until it was declared. Therefor A-Y addons wouldnt be added to her list. And if she wants to check for addons loaded status, theres an API for that. :/ I'm just trying to understand the purpose of the file the OP wants to know exists. |
We're checking the contents of a table, not setting up an automatic indexing metamethod. Two completely different things you're thinking there. Besides, all ADDON_LOADED events are visible to all addons, the name or load order of the one checking shouldn't generally matter.
Here's how the earlier example code works. Let's say I had an addon with the following structure: Code:
metaAddon.toc Here's what the table would look like. Code:
ns.loadedFiles = { It isn't meant to work with other addons at all - It's meant to keep track of which files within that specific addon are loaded. I went with the most obviously useful route, since Sideshow didn't specify - There's plenty of other tools for checking other addons, but not much in the way of checking for existence of files within your own. |
Hello
Because I'm to lame to include SharedMedia, I'm wondering if users could just drop their own font(s) in tinydps\fonts... so offcourse I need a way then to check if a certain file is loaded |
Quote:
|
Ofcourse that's possible. You supply one default font with your addon, let's say Arial.
Step 1. You put Arial.ttf in TinyDPS and rename it font.ttf. Step 2. You use Interface/AddOns/TinyDPS/font.ttf in your .lua file(s). Step 3. You tell your users if they want a different font they must place it in the TinyDPS folder and rename it to font.ttf. |
That's the dirty way ... :)
I was just curious if it would possible to drop in a random font file and then recognise/use it in my script. |
Quote:
Code:
isValid = FontInstance:SetFont("filename", fontHeight, "flags") Example snippet: Code:
local fonts, object = {}, CreateFont() You could also bruteforce aa, ab, ac, ba, zz, zzzzzzzzzzzzz, but that wouldn't be that efficient :p |
But then you would have to know the file name of the font in order to check if it was valid.
What's so hard about LSM support? |
All times are GMT -6. The time now is 09:12 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI