So i'm looking for a little help with this personal addon i made to enforce a list of cvars, keybinds and other fixes across all characters.
I am not really a coder, so i don't know much about this other than the most basic principles.

This mod should run these cvars when i log on a character as is.
Problem is that both config-cache.wtf and AdvancedInterfaceOptions has some of these cvars, and i want this to override any other settings set by either the game or other addons.
I'm not sure if this already does that by running on every character login entering the world, either way i want to be sure this works as intended.

Now i' thinking maybe i need either to name the mod so it is loaded after? before? all other mods, like calling it !MyCvars.
Or the code needs to be executed at a point later than what the game config and AdvancedInterfaceOptions does.

This will make it so that addon loads before yours. As for the config-cache.wtf, this is character specific settings that generally require a game restart to take into effect. You should be good to go once you add that to your toc.

This will make it so that addon loads before yours. As for the config-cache.wtf, this is character specific settings that generally require a game restart to take into effect. You should be good to go once you add that to your toc.

Does it matter the order the addon loads because the function isn't being called until PLAYER_ENTERING_WORLD, unless of course addons receive events in the order they loaded which I have no idea about.

Doesn't AIO only set CVars when you action them in its UI?.

That said, this function will fire every time you see a loading screen. If you want a single event when the game loads use PLAYER_LOGIN.

Does it matter the order the addon loads because the function isn't being called until PLAYER_ENTERING_WORLD, unless of course addons receive events in the order they loaded which I have no idea about.

Doesn't AIO only set CVars when you action them in its UI?.

That said, this function will fire every time you see a loading screen. If you want a single event when the game loads use PLAYER_LOGIN.

Frames get events in the order they were registered. If you want a frame to always go last when an event registers, you can find a way to occasionally call UnregisterEvent then RegisterEvent right after, such as in ADDON_LOADED or UNIT_AURA or something like a 5 second OnUpdate. There’s some chat update events that are spammed during loading between ADDON_LOADED and PLAYER_LOGIN you could use if you’re confident addons wouldn’t try to register afterwards.

If you want to ensure your frame goes first, you can do the same thing but with the first return of GetFramesRegisteredForEvent("event"), which returns an ordered list of frames, the first one being the first one that was registered.

AIO has an option to "enforce" all cvars that were set the last time you logged out, so temporary and character-specific cvars get reapplied the next time you log into any character.

It's meant to keep a global list of settings so if you change something it stays changed across your whole account.

Originally it was intended to prevent other addons from modifying cvars that you set manually through AIO, but I modified it to allow the changes but track which addon last touched the cvar so you can see it in the cvar browser.

Loading after AIO does might not always work. It reapplies the settings only after both VARIABLES_LOADED and ADDON_LOADED fires for it. If VARIABLES_LOADED fires after ADDON_LOADED does, setting it as an optional dependency won't be enough, and you'll have to wait for VARIABLES_LOADED to fire before overriding the settings.

Unfortunately, tracking settings that addons apply before AIO loads is considerably more complicated than the current setup, and would probably actually require loading a separate module before any other addons load, so it hasn't been done yet.

Also, this seems like a lot of personalized settings for an addon to change if this is something that's going to be distributed to other people, and the exact reason AIO tracks which addon modified which cvar, because these are things that persist after your addon is disabled and people get confused about why their settings are all different from what they had set when they turn it off and it doesn't go back to the way it was before.

Also, this seems like a lot of personalized settings for an addon to change if this is something that's going to be distributed to other people, and the exact reason AIO tracks which addon modified which cvar, because these are things that persist after your addon is disabled and people get confused about why their settings are all different from what they had set when they turn it off and it doesn't go back to the way it was before.

It sounded to me like they wanted to ensure it would override settings set by any addons. Though I guess my point is moot because OP is using AIO, but other people finding this thread from Google might not be.

It sounded to me like they wanted to ensure it would override settings set by any addons. Though I guess my point is moot because OP is using AIO, but other people finding this thread from Google might not be.

If this is the case then loading later in the loading process won't be enough to really solve this problem.

Since any addon can change any cvar at any point while the game is running, to actually prevent a cvar from being changed requires actively monitoring for any future cvar changes and reversing them (which could cause an infinite loop if someone else has the same idea that their settings are actually more important than your settings and tries to reinforce them too), and would prevent you from doing things like toggling nameplate visibility on the fly (although I believe those are combat-protected so you'd have to take that into account as well).

To anyone finding this thread later: Don't automatically change cvars in your addon unless you have a very good reason to do so, and make it clear to your users that this is something you're doing.

These settings are generally permanent, and many of them can't be set through the interface, so even if your addon is disabled its changes will remain in-place and not easily reverted.

To anyone finding this thread later: Don't automatically change cvars in your addon unless you have a very good reason to do so, and make it clear to your users that this is something you're doing.

These settings are generally permanent, and many of them can't be set through the interface, so even if your addon is disabled its changes will remain in-place and not easily reverted.

Can SetCVar be called at PLAYER_LOGOUT?
If so, I imagine a (partial) solution to this could be for an addon author to revert affected CVars back to defaults at logout.
Partial, because it wouldn't work if the user incorrectly exited the game before removing the addon, without explicitly logging out properly, but for the average user, this would effectively ensure that any changes to CVars from the addon wouldn't remain after uninstalling.

Can SetCVar be called at PLAYER_LOGOUT?
If so, I imagine a (partial) solution to this could be for an addon author to revert affected CVars back to defaults at logout.
Partial, because it wouldn't work if the user incorrectly exited the game before removing the addon, without explicitly logging out properly, but for the average user, this would effectively ensure that any changes to CVars from the addon wouldn't remain after uninstalling.

I'm just thinking/typing out loud, but what if you set a flag when PLAYER_LOGOUT is properly used or exited? If the player exits improperly, then the app would know that things didn't end well and make changes appropriately.

I'm just thinking/typing out loud, but what if you set a flag when PLAYER_LOGOUT is properly used or exited? If the player exits improperly, then the app would know that things didn't end well and make changes appropriately.

Wouldn't really help anyway, even if it worked, because the hypothetical situation is that the user removed that addon following a crash.
Remove the addon, and you'd also be removing the code which would be checking for said flag anyway. So there isn't really a point, heh, and if you aren't removing the addon it'll just resume proper functionality the next time you start the game.

btw, probably a stupid question: X-ing out of the game improperly exits the game and doesn't save saved variables, right? I can imagine a lot of less knowledgeable players doing just that in the same way that people remove usb devices without doing the whole "remove safely" thing first.

btw, probably a stupid question: X-ing out of the game improperly exits the game and doesn't save saved variables, right? I can imagine a lot of less knowledgeable players doing just that in the same way that people remove usb devices without doing the whole "remove safely" thing first.

Alt-F4ing out of the game does not prevent it from writing to the disk before it exits, unless it crashes during the process.

EDIT: What I say bellow is WRONG. See Ammako's reply immediately bellow for details.

Originally Posted by Torhal

Improper exit means the game crashed, which means no disk write.

You can set the flag to work reversely. I.e.:
1. Check the saved flag, say "cleanExit", and do the necessary fixups if it's false or nil;
2. Set cleanExit to false upon PLAYER_LOGIN;
3. Change the CVars and whatnot;
4. Set cleanExit to true on PLAYER_LOGOUT.
The absence of write on game crash implies NO evidence of a clean exit.

You can set the flag to work reversely. I.e.:
1. Check the saved flag, say "cleanExit", and do the necessary fixups if it's false or nil;
2. Set cleanExit to false upon PLAYER_LOGIN;
3. Change the CVars and whatnot;
4. Set cleanExit to true on PLAYER_LOGOUT.
The absence of write on game crash implies NO evidence of a clean exit.

Game crash = no disk write, including step 2.

You could have that variable set to true at login, change it to false at step 2. Game crashes, the change isn't saved, and it will still be set to true.

Saved Variables don't get written to until you reload/logout/exit the game, no matter how many changes you make.