Thread Tools Display Modes
01/09/16, 06:17 PM   #1
vandel212
Join Date: Jan 2016
Posts: 17
Prevent Certain Saved Variables from loading

I have an addon where is saves data outside of the game via saved variable. However once it is saved, I do not want the addon to use it anymore. Is it possible so that when loading addons, it does not load all of the saved variables?
  Reply With Quote
01/09/16, 10:00 PM   #2
Ayantir
 
Ayantir's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 1,019
No, ask to author. Of you're the one, juste rewrite your code and don't use it?
  Reply With Quote
01/10/16, 06:29 AM   #3
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,960
After reading and using it you could just erase it by setting the appropriate savedvariables table content to nil.
If I remember right all nil variables will be "removed" on next savedvariables dump.
  Reply With Quote
01/10/16, 04:50 PM   #4
vandel212
Join Date: Jan 2016
Posts: 17
Originally Posted by Baertram View Post
After reading and using it you could just erase it by setting the appropriate savedvariables table content to nil.
If I remember right all nil variables will be "removed" on next savedvariables dump.
Well I still need them to exist in the file, setting them to nil removed that line from the file altogether.
  Reply With Quote
01/11/16, 04:44 AM   #5
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,960
I do not want the addon to use it anymore
Ok, I read this sentence as "destroy the info"

If you've loaded the data into the addon and don't want the addon to react on it anymore, why do you still need it then? Could you explain what you are trying to do in detail so we can help you better?

Without knowing the details:

You could either set a flag into the savedvariables for this/these entries as they were loaded the first time properly, and react on the flag afterwards.

Or you could move the content of this savedvariables table to a second savedvariables table (like a backup) and use the 2nd savedvariables table then for your checks against the data that you have loaded before.
If the 1st savedvariables doesn't hold the data you can check the 2nd savedvars and this way you know they were read before already and transferred to 2nd saved vars.

To build different SavedVariables you can either change the version number to different ones (one for your current addon versin and one fixed to 999 e.g.), or just specify a different "key" for the SavedVariables, where the data should be saved:

Lua Code:
  1. local addon.settings = ZO_SavedVars:NewAccountWide(addon.name .. "_Settings", addon.version, "Settings", defaultSettings)
  2.  
  3. local addon.transferedSettings = ZO_SavedVars:NewAccountWide(addon.name .. "_TransferredSettings", addon.version, "TransferredSettings", defaultSettings)

You are able to check the "[TransferredSettings]" array in the SavedVariables <addonName>.lua file then for your "backup settings".
  Reply With Quote
01/15/16, 01:50 AM   #6
vandel212
Join Date: Jan 2016
Posts: 17
Originally Posted by Baertram View Post
If you've loaded the data into the addon and don't want the addon to react on it anymore, why do you still need it then? Could you explain what you are trying to do in detail so we can help you better?
So here is what I am doing. I'm gathering data and then having another application outside of ESO look at this then do some processing. So my workflow thus far is, go in game, do some stuff, have it save all the information, and reload the ui so it actually saves to the file. Then the external program processes the saved variables.

That works as expected. I do not want the external program to process the information again, so I'd like to have it clears out each line of the saved variable file that it processes. The issue is that once the user either reloads the UI or exits the game the lines of the saved var file are entered back in to the file. This would cause the external program to process them again next time. There are less attractive ways of getting around this, like checking to see if it's been processed already based on a unique ID, or forcing the user to shut down ESO before running the external application, but those are clunky ways of doing it. I'd rather be able to delete the line in the lua file without it showing up again and never have to worry about it.

So essentially, I'd like ESO to write the saved variables to the file, then forget they exist so that the external program's edits to the saved variables file won't be overwritten.

Last edited by vandel212 : 01/15/16 at 01:54 AM.
  Reply With Quote
01/15/16, 02:19 AM   #7
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,960
Maybe save the data in the SavedVariables file in kind of groups and add a suffix to the group name (like "_PROCESSED") if the data has been processed by your external program.
The next time your addon checks, if the data for this group must be updated, it will only update the group if the "_PROCESSED" is not present at the end of the name (regex check e.g.).

Though this would keep several empty groups in the SavedVariables. But you could easily rename the "_PROCESSED" groups in your SavedVars, by the help of an addon, to force the update of the data again for newer data for your external program.
  Reply With Quote
01/15/16, 02:45 AM   #8
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 577
Well, Saved-Variable-files get overwritten from in-memory data, but source-files not.
You could used a source-Lua-file as a data-file, which tells your addon which data to remove upon (re-)load.

You could alter between two tables and the source file, altered by our external program, tells which to fill and which to clear.
  Reply With Quote
01/15/16, 05:48 AM   #9
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
Votan's idea is brilliant. Although it could still suffer small inconsistencies when e.g.:
export_to == 1
add-on saves data into table 1
reloadui
add-on still uses table 1
external app reads table 1, sets export_to = 2
you need to reloadui again to make add-on wipe table 1 and use table 2

Here's my suggestion: save it in time-stamped tables

Lua Code:
  1. -- ON_ADD_ON_LOADED
  2. local prune_stamp = tonumber(EXTERNAL_APP_SEEN_DATA_UNTIL) or 0
  3. for key in next, saved_vars do
  4.   key = tonumber(key)
  5.   if key and key <= prune_stamp then
  6.     saved_vars[key] = nil
  7.   end
  8. end
  9.  
  10. local now = GetTimeStamp()
  11. local new_data_table = {} -- gather new data in this table
  12. saved_vars[now] = new_data_table

The external app would then, after reading the saved vars, alter the special file export_timestamp.lua inside your addon (note: missing file is not an error, so it doesn't need to exist until your app creates it; it doesn't have to be shipped with the addon, just list it in the manifest):
Lua Code:
  1. -- make this identifier unique,
  2. -- or put in in your add-on global table if it has one
  3. EXTERNAL_APP_SEEN_DATA_UNTIL = 123456789
  4. -- the highest timestamp it has seen

It would still take a second reloadui to actually wipe that data from saved vars, but it wouldn't wipe the data gathered between the 1st and 2nd reloadui.
  Reply With Quote
01/15/16, 01:06 PM   #10
dopiate
AddOn Author - Click to view addons
Join Date: Jun 2014
Posts: 142
I think this is already being done.....

Originally Posted by vandel212 View Post
So here is what I am doing. I'm gathering data and then having another application outside of ESO look at this then do some processing. So my workflow thus far is, go in game, do some stuff, have it save all the information, and reload the ui so it actually saves to the file. Then the external program processes the saved variables.

That works as expected. I do not want the external program to process the information again, so I'd like to have it clears out each line of the saved variable file that it processes. The issue is that once the user either reloads the UI or exits the game the lines of the saved var file are entered back in to the file. This would cause the external program to process them again next time. There are less attractive ways of getting around this, like checking to see if it's been processed already based on a unique ID, or forcing the user to shut down ESO before running the external application, but those are clunky ways of doing it. I'd rather be able to delete the line in the lua file without it showing up again and never have to worry about it.

So essentially, I'd like ESO to write the saved variables to the file, then forget they exist so that the external program's edits to the saved variables file won't be overwritten.

Maybe I'm reading this wrong but I think I'm already doing this in my program in coordination with Master Merchant.

Master Merchant gathers all sales from everywhere and when it finds a NEW sale that is from the current user, it then sends that eventID to the Guild Sales Assistant in game portion, which then gets the details it needs then sorts and saves the sales in a slightly different format that MM.

Master Merchant uses the sales id and date as the variables to sort out "new" sales, so in game it never sends Guild Sales Assistant any old sales.

Then the offline component of Guild Sales Assistant (GSA) parses the guildsalesassistant.lua saved variables and from that information it only gathers the new sales and puts them into the GSA "offline" database called GuildsalesassistantDB.lua (which is not LUA actually but just a good safe spot to store the flat file database).

So there are actually two examples of using just the new data and not deleting anything existing done both in-game and out of game.

Unless I'm missing something, which is always possible since my English language skills are terrible, you have two programs with two different solutions working together that you could use as an example or borrowed code for what you are trying to do.

In game MM never sends GSA anything but new data and GSA offline never processes any old data.

I understand you want to manipulate the existing savedvariables.lua file, but I went down that road in the very early days of GSA (pre-MM) and it caused lots of unexpected problems.

When you state:

Originally Posted by vandel212 View Post
There are less attractive ways of getting around this, like checking to see if it's been processed already based on a unique ID, or forcing the user to shut down ESO before running the external application, but those are clunky ways of doing it. I'd rather be able to delete the line in the lua file without it showing up again and never have to worry about it.
How exactly is keeping the old data (as backup or a double check) "clunky" ?

Just purge your saved variables based on a date. MM uses 30 days by default but you could do it for 2 days or 1 day or hourly depending on your goal.

If I missed the mark here, my apologies, but to me it seems like your trying to do what Philgo68 and I have already done, no?

Why re-invent the wheel, have a look at the code, maybe you can use some of it and save yourself some time?

Just trying to help :-)

-d

Last edited by dopiate : 01/15/16 at 01:26 PM.
  Reply With Quote
01/15/16, 05:35 PM   #11
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
Originally Posted by vandel212 View Post
So here is what I am doing. I'm gathering data and then having another application outside of ESO look at this then do some processing. So my workflow thus far is, go in game, do some stuff, have it save all the information, and reload the ui so it actually saves to the file. Then the external program processes the saved variables.

That works as expected. I do not want the external program to process the information again, ...
If I understand this correctly, why not just set a flag in your saved variables?
Lua Code:
  1. mySavedVars= {
  2.    exportData = false,
  3.    
  4.    -- whatever other data you have
  5. }

Then create a button or a slash command that sets the flag & reloads the ui.
Lua Code:
  1. SLASH_COMMANDS["/backupdata"]   = function ()
  2.    -- Set flag so data is backed up
  3.    mySavedVars.exportData = true
  4.    ReloadUI("ingame")
  5. end

Then when the UI reloads reset the saved variable to false so it won't backup the data again.
Lua Code:
  1. mySavedVars.exportData = false

Then all you have to do is have your external program check for the exportData flag and only process it if it is true.

Or you could create a backup table in your saved vars. Use a custom reloadUI slash command like above and before it reloads the ui copy all of the data you want to backup into the backup table
Lua Code:
  1. mySavedVars = {
  2.    backupData = {}
  3.  
  4.    --- other stuff
  5. }
and then on player activation wipe out the bakcupData table. Since the backupData table is just a copy you would still retain all of the original data in your saved vars. Then just have your external program only copy whats in the backupData table.

Either way when the game is reloaded normally either the exportData flag is false or the backupData table is empty, depending on which method you use, no new data will get exported and you will still retain the original data in saved vars.

Last edited by circonian : 01/15/16 at 05:44 PM.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Prevent Certain Saved Variables from loading

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off