- Home /
I can't save because of the this keyword
Essentially I followed a Brackeys tutorial in order to create my save data script.
public void SaveState()
{
SaveSystem.SaveGameData(this);
}
It works great, but only with buttons. For example if I want to use another script to save the game on start it won't work.
SettingAndValue.SaveState();
Normally I would get around this by making it a public static void, but the "This" keyword is preventing me from doing that. I read a bunch of stuff talking about "Form 1" but I have no idea what the heck that is and nothing explained it properly, and besides I don't really care much anyway.
IDEALLY I would want to replace the "this" keyword with something else, but I don't know what is supposed to go there, it isn't the class name so then what is it?
Just add a parameter to your script:
public void SaveState([Whatever type is your "this" class ScriptableObject etc.] param)
{
SaveSystem.SaveGameData(param);
}
So when you call this method somewhere out of your script just pass the parameter.
Thanks for the reply, but how do I know what the Type of "this" is? Also you used brackets in your answer, do I need to use brackets for something?
@mchts could you dumb it down a little please? I'm small brain.