Need help understanding why loop is not always processing entire table
I'm in the process of creating my first addon and teaching myself lua... I'm not an expert by any means so any help would be appreciated.
The addon I'm creating is a simple mount collection log which mimics the functionality that simple armory mount collection shows. It lists all the obtainable mounts, categorizes them and marks off those you have collected. I've managed to get the main GUI and functionality sorted but it's not performing consistently. Meaning sometimes when you initialize the addon, the entire lua table has not been processed leaving a lot mounts missing in the GUI. This issue is less of a problem when there are no addons enabled, but happens a lot more when there are other addons enabled at the same time. The main function of the code is below, I imagine the problem is to do with how many loops there are. Any help is appreciated. I can provide the entire files if need be. Lua Code:
|
Hi and welcome! :)
You could try executing your code after PLAYER_LOGIN like this: Lua Code:
|
Unfortunately I've already tried using that event trigger. I have better results with ADDON_LOADED trigger, however, still having issues with not all frames being created consistently.
|
Are you checking which addon is loaded when using the ADDON_LOADED trigger? Maybe you have to wait for Blizzard_Collections to be loaded, but that's just a very wild guess.
It's difficult to understand your code. For example, you are traversing a table called "mountList". I guess that is the table you say is sometime not fully traversed? Your code does not show where you are getting "mountList" from in the first place. |
1 Attachment(s)
So the code I'm using for the ADDON_LOADED trigger is
Lua Code:
My mountList, SectionNames are tables provided in a different file and they look like this. Lua Code:
Yes I would say that is the table that is not always fully traversed. I've just tried adding a LoadAddon line for Blizzard_Collections inside the core.init function Lua Code:
Still the same result. Attached is the addon, if anyone would take a look I would be appreciated. |
You are still not making sure that you are only accessing the collection information after the collection addon is loaded. You are checking for MCL addon is loaded but not checking if Blizzard_Collections addon is loaded before accessing its data. It might be that the first few accesses are failing in some way, do you have an error catch system like bugsack/buggrabber so that you can see if there are any particular errors that occur on that first access attempt.
Suggestions: 1. Install bugsack/buggrabber addons or any equivalents you may be aware of and prefer .. 2. In your event loop checking if the Blizzard_Collections addon is loaded and then do your collections related coding. 3. Make use of print statements to check what values are between code lines to see if values change and perhaps highlighting potential reasons why. - Just remember to remove them or put them in a if debug statement before releasing the addon if you plan to . |
1. I already had bugcatcher/bugsack installed and been using it a lot. No errors pop up when it misses data.
2. I've added the code below (has no effect on the outcome). Lua Code:
Have I done that correctly? This has had no effect on the original issue. |
You've set up your data tables (sectionNames and mountList) as globals. They should really be included in your namespace table (core.sectionNames and core.mountList).
You could add the collection loaded check to MCL_Load:CreateMenu() before creating the frame and get rid of the whole init frame ADDON_LOADED stuff and just use the slash command Lua Code:
Lua Code:
The "Welcome back" message is not really needed, they know they are playing and using your addon if they've gotten this far so... ;) You're also using a lot of globals with names like totalCollected and u and total and x and y ... While it's easy for accessing data in various parts of your code, you really need to make sure that global names are absolutely unique to your addon MCL_totalCollected, MCL_u, MCL_total etc. It may not be the cause of you problems but it will help stopping future possible problems. |
1 Attachment(s)
Really appreciate everything so far guys, really helped me understand a few things. I've gone through and removed all my globals.
I've attached the current version as I'm still having issues with the entire mount table not being loaded consistently. Sometimes no mounts get loaded, sometimes 100-200, sometimes all of them. I can't seem to figure out why it varies. Thanks so much for the replies so far guys. |
1 Attachment(s)
You have a timing problem between when you ask for data and when it is ready to use.
I couldn't find an event that worked to tell you when the mount information has been cached so I bodged something up (not really tested so...) I also moved the update code into a function to be used OnShow so it gets update each time the Config. frame is displayed. Attachment 9665 I hope it gets you closer. Edit: I didn't check on things like frame creation so you might be getting new icon frames created on top of older ones each OnSHow and stuff like that. |
Fizzlemizz, thank you so much for this. Calling for the data on addon_load seems to have fixed it.
|
All times are GMT -6. The time now is 05:47 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI