WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   SavedVariables forced write (https://www.wowinterface.com/forums/showthread.php?t=57897)

doofus 03-31-20 06:21 AM

SavedVariables forced write
 
I would like to save data in a file to be read externally. This is possible by assigning to a "SavedVariables" variable, but I cannot force it to write to the file on demand. Well I sort of can, by "/reload", but is there a programmatic way?

Xrystal 03-31-20 06:28 AM

Quote:

Originally Posted by doofus (Post 335486)
I would like to save data in a file to be read externally. This is possible by assigning to a "SavedVariables" variable, but I cannot force it to write to the file on demand. Well I sort of can, by "/reload", but is there a programmatic way?

Nope. The Saved Variables are loaded into memory on Login and saved on Logout. Addons update the memory values during game play. The file will not be updated until you either log out to character screen ( for character based saved variables ) and all the way out ( for game based saved variables ).

Fizzlemizz 03-31-20 08:30 AM

/reload also causes saved variables to be eeerrrr... saved.

doofus 03-31-20 02:46 PM

Therefore, if an addon wants to communicate using an external file, it can only be done with "/reload" and/or real reload?

Fizzlemizz 03-31-20 03:20 PM

The addon can't communicate but the only way for an external program to extract the latest information from an addons SavedVariables file(s) is after /reload or logout/exit.

SDPhantom 03-31-20 10:45 PM

The function you're looking for is C_UI.Reload() (previously ReloadUI()). This requires a hardware event like a button click or a keybind.

This restriction of real-time communication outside of WoW is by design to prevent botting.

doofus 04-01-20 01:51 AM

Quote:

Originally Posted by Fizzlemizz (Post 335503)
The addon can't communicate but the only way for an external program to extract the latest information from an addons SavedVariables file(s) is after /reload or logout/exit.

I got the idea from the well known TSM addon, where, I presume, an external application writes to the saved variables file, to be read later by the addon itself. So the communication can be two ways, albeit with the /reload in between.

I have also noticed many times that WoW loses character settings if you do not log out but crash out/lose connection, which also follows the same "save files on /reload" rule...

myrroddin 04-01-20 01:56 AM

Quote:

Originally Posted by doofus (Post 335506)
WoW loses character settings if you do not log out but crash out/lose connection

Of course, because that is not a "clean" exit of the game, therefore the instruction to write to disc never happens.

Think of writing the Great Novel then pressing alt-f4. Except that in WoW there is no periodic automatic save.

Xrystal 04-01-20 02:01 AM

Quote:

Originally Posted by myrroddin (Post 335507)
Of course, because that is not a "clean" exit of the game, therefore the instruction to write to disc never happens.

Think of writing the Great Novel then pressing alt-f4. Except that in WoW there is no periodic automatic save.


Or in the middle of writing your first game ... and the power goes before you save and that large 300 lines of code are gone in the wind ... *cries*

Xrystal 04-01-20 02:09 AM

Quote:

Originally Posted by doofus (Post 335506)
I got the idea from the well known TSM addon, where, I presume, an external application writes to the saved variables file, to be read later by the addon itself. So the communication can be two ways, albeit with the /reload in between.

I have also noticed many times that WoW loses character settings if you do not log out but crash out/lose connection, which also follows the same "save files on /reload" rule...


Yes, using reload in an addon ( via a button click ) or /reload command, will force an update of the saved variables. So that in the event of a crash out before the next reload you will have at least have up to the last save done. Unfortunately, any changes you make while you are still in the game will not be registered. You would have to log out ... update the file if needed ... log in. At that point it will load the updated file.

Hopefully these 3 scenarios will highlight why what you want will only work as an autosave type thing ( with a button press or slash command ) or as an external reader/writer of the file while the game is not running.

Log In > Saved Variables File Loaded into memory
Reload > Saved Variables File Updated from memory and loaded into memory
Crash .... > No change to Saved Variable File

Log In > Saved Variables File Loaded into memory
Reload > Saved Variables File Updated from memory and loaded into memory
External Program > Saved Variables File adjusted via program
Reload > Saved Variables File Updated from memory, replacing changes made by program, and then loaded into memory

Log In > Saved Variables File Loaded into memory
Log Out > Saved Variables File Updated from memory
External Program > Saved Variables File adjusted via program
Log In > Saved Variables File Loaded into memory including the changes mae by the program


All times are GMT -6. The time now is 05:28 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI