Thread Tools Display Modes
11/15/23, 07:06 PM   #1
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 245
Question update character variable on all chars at once?

Looking for a way to update char saved variables all at once while logged into only one toon.

I'm currently running mostly an account wide setup but have a few char specific variables id like to reset at server daily reset. I'm currently saving the per char variables like this:
Code:
ZO_SavedVars:NewAccountWide( MyAddon.svName, MyAddon.svVersion, GetUnitName("player"), defaultSavedCharVars )
MyAddon.charVariables.myvariable = something
what Id like to use is something like this to go through every character on account and set a specifici char variable at daily login which I have the code for already I'm just unsure how to save a char variable for a toon your not logged into:
Code:
function MyAddon.ResetCharacterData()
	for i = 1, GetNumCharacters() do
		local charName = GetCharacterInfo(i)
                charName = charName:sub(1, charName:find("%^") - 1)
		MyAddon.charVariables.charName.myvariable = something
	end
end
Basically in short I'd like to cycle through all characters on acct with a for statement resetting 2 char variables to 0 at daily reset time. Any suggestions?

Last edited by sinnereso : 11/16/23 at 02:32 AM.
  Reply With Quote
11/16/23, 03:01 AM   #2
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,989
SV is a global table with the name you specify at the txt file per ## SavedVariables: <globalName>

So your can read your sv file on the disk and you see the contents like
<globalName> = {
["@AccountName"] = {
["Charactername here"] = { ....


Just update it like this then:
<globalName>["@AccountName"]["Charactername here"]["variableName"] = xyz

Last edited by Baertram : 11/16/23 at 04:01 AM.
  Reply With Quote
11/16/23, 03:15 AM   #3
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 245
Originally Posted by Baertram View Post
SV is a global table with the name you specify at the txt file per ## SavedVariables: <globalName>

So your your sv file on the disk and you see the contents like
<globalName> = {
["@AccountName"] = {
["Charactername here"] = { ....


Just update it like this then:
<globalName>["@AccountName"]["Charactername here"]["variableName"] = xyz
I have accountwide and character variables already set up.. I guess what I'm asking is is it possible to edit "char1" char variable from "char2" and how?

my variables are setup like this:
Code:
MyAddon.savedVariables = ZO_SavedVars:NewAccountWide( MyAddon.svName, MyAddon.svVersion, nil, defaultSavedVars )
MyAddon.charVariables = ZO_SavedVars:NewAccountWide( MyAddon.svName, MyAddon.svVersion, GetUnitName("player"), defaultSavedCharVars )
is it possible to do a "MyAddon.charVariables.something = something" to save something on each characters variables from a single character?

Last edited by sinnereso : 11/16/23 at 03:25 AM.
  Reply With Quote
11/16/23, 03:50 AM   #4
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,989
Please re-read what I described above!
I'm not talking about your ZO_SavedVars wrapper which you're already using. I'm talking about "global tables" in lua code!
The ZO_SavedVars wrapper just handles the GetDisplayName() to get your @AccountName and GetCurrentCharacterId() to get the characterId for you and then updates the "global SV able of your addon, specified at ## SavedVariables: <globalTableName>" for you.
But <globalTableName> can be read and changed directly too!

Try /tbug <globalTableName> and you see your SV table in merTorchbug.
Try /tbug MyAddon.charVariables to see the difference where ZO_SavedVars was used as a wrapper around the table.

Check your SV file on the disk to get the correct table name, subtables etc. and then simply access it like described, directly, without ZO_SavedVars usage or any pointer variable like your MyAddon.charVariables or MyAddon.savedVariables

You can do both: With ZO_SavedVars and without, even at the same addon.

Last edited by Baertram : 11/16/23 at 04:08 AM.
  Reply With Quote
11/16/23, 05:16 AM   #5
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 245
TY and I have been re-reading it. But.. Ive decided to revert back to a simple single acct wide variable. TY for all the help
  Reply With Quote

ESOUI » AddOns » Released AddOns » update character variable on all chars at once?


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