ID:1403988
 
(See the best response by Ter13.)
Code:
mob/proc
SaveOptions()
var/savefile/F=new("Options/[src.ckey].sav")
Write(F)
F["MusicOn"] << src.MusicOn
F["PlayMusicOn"] << PlayMusicOn
F["PlayMusicOff"] << PlayMusicOff
LoadOptions()
var/savefile/F=new("Options/[src.ckey].sav")
if(F)

F["MusicOn"] >> src.MusicOn
F["PlayMusicOn"] >> PlayMusicOn
F["PlayMusicOff"] >> PlayMusicOff

//where it's being called

mob/verb
PlayMusic()
set hidden = 1
if(usr.MusicOn==1)
winset(usr,"Options.MusicOn","image=[PlayMusicOff]")
winset(usr,"Options.MusicOn","size=26x13")
usr.MusicOn=0
usr.CheckMusic()
usr.SaveOptions() ; world<< "I'm saving off"
else if(usr.MusicOff==0)
winset(usr,"Options.MusicOn","image=[PlayMusicOn]")
winset(usr,"Options.MusicOn","size=22x13")
usr.MusicOn=1
usr.CheckMusic()
usr.SaveOptions() ; world<< "I'm saving on"

mob
Login()
..()
winset(usr,"default.MChild","left=MainMenu")
if(beta_list.Find(usr.key))
usr<<"<font color=gold>Welcome to BETA Testing, [src.key]."
Online+=src
OnlineCurrent+=1
usr.loc=locate(7,3,1)
usr.freeze=1
usr.LoadVote()
usr.ChangeMusic()
usr.CheckMusic()
world<<voted_game
if(fexists("Options/[src.ckey].sav"))
world<<"I'm calling load"
usr.LoadOptions()

//vars if needed
var/
PlayMusicOn='PNGS/MusicOn.png'
PlayMusicOff='PNGS/MusicOff.png'
mob/var/
MusicOn=1


Problem description:The saves themselves don't load. I reboot and it goes right back to the music being on when I had it off.

Not 100% sure why this is occurring, but any help would be appreciated.

Where is it that is turning the music on? Is that happening inside of "CheckMusic()" or "ChangeMusic()"? Because you're calling those before you're calling "LoadOptions()"
Best response
        if(usr.MusicOn==1)
winset(usr,"Options.MusicOn","image=[PlayMusicOff]")
winset(usr,"Options.MusicOn","size=26x13")
usr.MusicOff=1
usr.MusicOn=0
usr.CheckMusic()
usr.SaveOptions() ; world<< "I'm saving off"
else if(usr.MusicOff==1)
winset(usr,"Options.MusicOn","image=[PlayMusicOn]")
winset(usr,"Options.MusicOn","size=22x13")
usr.MusicOn=1
usr.MusicOff=0
usr.CheckMusic()
usr.SaveOptions() ; world<< "I'm saving on"


Stop and think about this for a second. What happens when MusicOn is equal to 1, and MusicOff is equal to 1?

You don't need MusicOn/MusicOff. You just need MusicOn as a variable.
I got the music to cut off, but the var to change the button image doesn't stick.
Did you move your loading instruction to above everything (including the line that sets the button image?)

It has to come first, before anything that uses the data.
You mean in the save file? Or where the save is programmed?
I just meant that this part:

if(fexists("Options/[src.ckey].sav"))
world<<"I'm calling load"
usr.LoadOptions()


Needs to be one of the very first things you do in Login(), to make sure that all of the options are loaded prior to anything being done (like the music playing, the button image being set, etc.)

But I see now that the button image is being set in PlayMusic(), and I presume that is being called after the loading should be done, so I guess that's not the issue here.
PlayMusic is the command for the button itself. Other then that, I'm more than sure it isn't called anywhere else.

I'm stumped on why the image isn't saving though.
Oh! So do you have another winset() call somewhere to set the button's image?

I don't think it'll do it on its own. You may need a winset() call to set it right in Login().

The var is probably saving and loading just fine. It looks like your code is just not set up to use it.
So, If I did it like..

mob
Login()
..()
winset(usr,"default.MChild","left=MainMenu")
if(fexists("Options/[src.ckey].sav"))
world<<"I'm calling load"
usr.LoadOptions()
if(usr.MusicOn==1)
winset(usr,"Options.MusicOn","image=[PlayMusicOn]")
winset(usr,"Options.MusicOn","size=22x13")
else if(usr.MusicOn==0)
winset(usr,"Options.MusicOn","image=[PlayMusicOff]")
winset(usr,"Options.MusicOn","size=26x13")


Would that work out well?
Ugh, DO NOT use usr in Login().

Use src. Usr is only meant to be used in verbs that are not meant to be used by the src object, and in click procs.
In response to Marcus55
Marcus55 wrote:
So, If I did it like..

> mob
> Login()
> ..()
> winset(usr,"default.MChild","left=MainMenu")
> if(fexists("Options/[src.ckey].sav"))
> world<<"I'm calling load"
> usr.LoadOptions()
> if(usr.MusicOn==1)
> winset(usr,"Options.MusicOn","image=[PlayMusicOn]")
> winset(usr,"Options.MusicOn","size=22x13")
> else if(usr.MusicOn==0)
> winset(usr,"Options.MusicOn","image=[PlayMusicOff]")
> winset(usr,"Options.MusicOn","size=26x13")
>

Would that work out well?

I think that should do the trick (aside from usr misuse, as Ter13 kindly reminded me just now).

One question now, though; will the PlayMusicOff and PlayMusicOn vars ever reference any other image files than the ones you have defined?

If the "Off" image and the "On" image will always be the same (respectively), then there's really no need for a var at all. You could just hardcode the images right into those winset()s and get rid of the vars entirely.
Okay. The images save now :D and thanks for telling me about the usr/src thing. The only thing I noticed with the turning it off and on was a moment of freeze/lag. Which should be an easy fix.