Script to refresh an addon
Hi,
I created an addon to make changes to my UI and Sound depending on the state of my character (in combat/ out of combat/ resting), unfortunately the addon only works at the point in time where my character changes state, like when my character enters combat or walks into an inn for example. However, if I log into game when my character is in the Inn then the UI and sound are not as required and I have to leave the Inn and enter it again for the changes to be made. Is there a script that can be added to the addon that checks the status of the character regularly and updates as required? https://pastebin.com/rNStNC0r Thanks in advance |
Delay registering your PRD and PUD events until after either ADDON_LOADED or PLAYER_ENTERING_WORLD. You are likely registering PRD and PUD too early in the loading process. I'd use PEW to be on the safe side; it is late enough in the loading process that most other events will function when hooked.
Side note: you don't need to create 3 frames. Create one, register PEW on it, register the other events during PEW, and check if event == blah, elseif event == blah2, elseif event == blah3, end. |
Also consider that some in game changes may not apply without a reload, even if activated at the right time.
|
I think the event registering is fine aside from the use of multiple frames when one would do. The issue is these events fire when the state changes, if you're already in certain states when your addon loads, the events won't fire.
As for event suggestions mentioned previously, ADDON_LOADED fires when all of an addon's files have been loaded and the main chunk of all of its Lua files has been executed. This also signifies that SavedVars for the addon has been loaded as well. PLAYER_ENTERING_WORLD fires any time when a loading screen finishes. This has historically been used to delay a loading process to when player data is available, but there is another event more suited for that. PLAYER_LOGIN fires specifically when general player data is accessible. Lastly, your code produces 4 states in which one creates a conflict with itself. This is when you're in combat in a rested area. Here's some sample code along with some optimization. Lua Code:
I don't know what you intend to do with the camera now the code has been fixed to 3 states, prioritizing combat mode over rested and resolving the conflict between the two. I believe camera zoom conflicts with SetView(), so some additional tweaking may be required. It's also a good idea to put values you may want to tweak later as constants at the top of the file. Especially with larger projects, you'll thank yourself if you want to change these months later and forgot all the places they're used in. |
All times are GMT -6. The time now is 04:26 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI