Thread Tools Display Modes
06-15-09, 04:41 PM   #1
Sythalin
Curse staff
 
Sythalin's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 680
Problems with vars saving

Run into an issue with profile swapping. Seems it's not saving.

Swap function:
Code:
function CFM_SwapProfile(realm, toon)
	if CFM_Profiles[realm] == nil or CFM_Profiles[realm][toon] == nil then
		print("CFM: No profile found.  Please make sure you've capitalized your realm and character name.")
		return
	end
	activeProfile = CFM_Profiles[realm][toon]
	activeProfile.useProfile = {realm, toon}
	print("CFM: Profile loaded for ".. realm.. " - ".. toon)
	for k,_ in pairs(activeProfile) do
		CFM_ApplySettings(k)
	end
	print(activeProfile.useProfile[2])
end
Loading function:
Code:
function CFM_OnEvent()
	local realm, toon
	toon = UnitName("player")
	realm = GetRealmName()
	if(event == "ADDON_LOADED") then
		if (arg1 == "CFM") then
			-- check for saved vars or create new
			CFM_Profiles = CFM_Profiles or {};
			CFM_Profiles[realm] = CFM_Profiles[realm] or {};
			CFM_Profiles[realm][toon] = CFM_Profiles[realm][toon] or {};
			CFM_Profiles[realm][toon].useProfile = CFM_Profiles[realm][toon].useProfile or {realm, toon}
			print("useProfile: "..CFM_Profiles[realm][toon].useProfile[2])
			print("toon: ".. toon)
			activeProfile = CFM_Profiles[CFM_Profiles[realm][toon].useProfile[1]][CFM_Profiles[realm][toon].useProfile[2]]
		end
	elseif (event == "PLAYER_ENTERING_WORLD") then
		if CFM_Loaded then
			for k,_ in pairs(activeProfile) do
				CFM_ApplySettings(k)
			end
		else
			CFM_Delay = true
		end
	end
end
Steps to reproduce
1) log into game
2) use slash command
3) /reload

Results
1) First time it'll swap and save properly through reload/relog
2) Any further attempts to swap after that will change the settings, but not save them through reload/relog.
  Reply With Quote
06-15-09, 04:53 PM   #2
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
I didn't read that thoroughly enough to know if this is actually what's causing your specific problem, but it probably is.

When you do:

Code:
table1 = table2
you're making table1 a reference to table2, so any changes to either will change both. If you want to create/update a separate table you need to do

Code:
table1 = CopyTable(table2)
  Reply With Quote
06-16-09, 05:22 PM   #3
Sythalin
Curse staff
 
Sythalin's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 680
Originally Posted by Akryn View Post
Code:
table1 = CopyTable(table2)
Although not the problem, but that's a nice tidbit to know for a different part of my code.

activeProfile already exists by the time the swap function is called as a reference.

For example. When I load up my main, it will assign
Code:
activeProfile = CFM_Profiles["Thunderlord"]["Sythalin"]
Now I swap the profile via "/cfm load Thunderlord Modtest". It properly reassigns the reference of activeProfile to CFM_Profiles["Thunderlord"]["Modtest"] and activeProfile.useProfile = {"Thunderlord", "Modtest"} (confirmed with the print() debugging).

Now, I /reload or logout. When I come back, it still loads activeProfile referencing CFM_Profiles["Thunderlord"]["Sythalin"], even though activeProfile.useProfile was rewritten to "Thunderlord, Modtest" before the reload/relog and should've been saved.

I've tried to reset it with activeProfile.useProfile = {} before the switch, but that didn't help either.
  Reply With Quote
06-16-09, 05:37 PM   #4
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
The modtest profile's activeProfile was switched to itself, but yours wasn't changed. Why not just keep a separate per-character variable that stores which profile should be active?
  Reply With Quote
06-16-09, 05:42 PM   #5
Sythalin
Curse staff
 
Sythalin's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 680
That's exactly what .useProfile is.

Saved vars:

Code:
CFM_Profiles = {
	["Thunderlord"] = {
		["Modtest"] = {
			["useProfile"] = {
				"Thunderlord", -- [1]
				"Modtest", -- [2]
			},
		},
		["Sythalin"] = {
			["VehicleMenuBar"] = {
				["strata"] = "MEDIUM",
				["point"] = "BOTTOM",
				["parent"] = "UIParent",
				["forceHide"] = false,
				["width"] = 869.0000005343184,
				["name"] = "VehicleMenuBar",
				["offsetY"] = 0,
				["offsetX"] = 0,
				["relativePoint"] = "BOTTOM",
				["sameXY"] = false,
				["level"] = 126,
				["height"] = 52.99999931301932,
				["scale"] = 0.699999988079071,
			},
			["restore"] = {
				["VehicleMenuBar"] = {
					["strata"] = "MEDIUM",
					["point"] = "BOTTOM",
					["parent"] = "UIParent",
					["width"] = 869.0000005343184,
					["offsetX"] = 0,
					["relativePoint"] = "BOTTOM",
					["height"] = 52.99999931301932,
					["offsetY"] = 0,
					["scale"] = 1,
					["level"] = 126,
				},
			},
			["useProfile"] = {
				"Thunderlord", -- [1]
				"Sythalin", -- [2]
			},
		},
	},
}
Unless I'm misunderstanding what you're trying to say.
  Reply With Quote
06-16-09, 06:01 PM   #6
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
Your swap code sets "activeProfile" to point to the modtest profile, and then it modifies activeProfile.useProfile -- which will *not* change CFM_Profiles["Thunderlord"]["Sythalin"].useProfile -- it will change CFM_Profiles["Thunderlord"]["Modtest"].useProfile -- and therefore when you reload the UI, it is still looking at what CFM_Profiles["Thunderlord"]["Sythalin"].useProfile has always been which is {"Thunderlord","Sythalin"}

You could fix that by tweaking your "swap profile" function a bit; but it would be *much* better to just add a

## SavedVariablesPerCharacter: blahblahblah

line to your .toc and save the name of the profile to use (and anything else you don't want to share between characters) there.
  Reply With Quote
06-17-09, 05:26 AM   #7
Sythalin
Curse staff
 
Sythalin's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 680
Originally Posted by Akryn View Post
Your swap code sets "activeProfile" to point to the modtest profile, and then it modifies activeProfile.useProfile -- which will *not* change CFM_Profiles["Thunderlord"]["Sythalin"].useProfile -- it will change CFM_Profiles["Thunderlord"]["Modtest"].useProfile -- and therefore when you reload the UI, it is still looking at what CFM_Profiles["Thunderlord"]["Sythalin"].useProfile has always been which is {"Thunderlord","Sythalin"}

You could fix that by tweaking your "swap profile" function a bit; but it would be *much* better to just add a

## SavedVariablesPerCharacter: blahblahblah

line to your .toc and save the name of the profile to use (and anything else you don't want to share between characters) there.
Except if the data will not share between characters, how would it be able to get the profile data? I did notice what you were talking about and changed it to

Code:
activeProfile.useProfile = {realm, toon}
activeProfile = CFM_Profiles[realm][toon]
so that (in theory) it would change the {realm,toon} before redirecting activeProfile. It's still changing useProfile for the other toon instead of the active one.

Gah, this is almost becoming a bigger pain in the ass than it's worth....

EDIT: HOLY CRAP. Just realized what you were actually talking about. Got it working now.

Code:
function CFM_SwapProfile(realm, toon)
	if CFM_Profiles[realm] == nil or CFM_Profiles[realm][toon] == nil then
		print("CFM: No profile found.  Please make sure you've capitalized your realm and character name.")
		return
	end
	CFM_Profiles[GetRealmName()][UnitName("player")].useProfile = {realm, toon}
	activeProfile = CFM_Profiles[realm][toon]
	print("CFM: Profile loaded for ".. realm.. " - ".. toon)
	for k,_ in pairs(activeProfile) do
		CFM_ApplySettings(k)
	end
end
Thanks for the help (and patience until I realized wtf you were referrring to).

Last edited by Sythalin : 06-17-09 at 05:57 AM.
  Reply With Quote
06-17-09, 05:53 AM   #8
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
Swapping the order won't help; you would need to check for your *current* realm/name because the ones you pass to that function are the ones you want to swap to.

Again, I suggest that you store the name of the profile for that character to use in a PerCharacter saved variable. The data would still be available to everyone, but each character would have their own per-character variable that just stored which profile that character should use.
  Reply With Quote
06-17-09, 06:07 AM   #9
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
EDIT: HOLY CRAP.
Yeah...I love it when that happens.
  Reply With Quote
06-17-09, 06:12 AM   #10
Sythalin
Curse staff
 
Sythalin's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 680
Originally Posted by Akryn View Post
Again, I suggest that you store the name of the profile for that character to use in a PerCharacter saved variable.
Ah, I see. I was misunderstanding; I thought you were meaning save everything per character. I may still do this as I'd love to clean up the saved vars a bit.

Last edited by Sythalin : 06-17-09 at 06:13 AM. Reason: I speaks good english well.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Problems with vars saving


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