Can't display variables

I don't really know how to describe this issue. But, basically, whenever I try to use the "$game_variables", it gives me an error. Specifically, a "NoMethodError" with an "undefined method '[]=' for nil:NilClass". If it helps at all, I'm borrowing a Global Save File script from here: https://www.rpgmakercentral.com/topic/6462-global-save-file-~-by-skul_/ .
This specifically is where the error occurs.

Code:
def self.loadVariables(f)
    for i in VARIABLES_TO_SAVE
        $game_variables[i]= f.getVar(i)
    end
end

I can provide more if it's needed. But any help would be appreciated.
when and where do you use the code?

Variables are only defined on a new game, any code that is executed before that moment will result in such an error
when and where do you use the code?

Variables are only defined on a new game, any code that is executed before that moment will result in such an error

Oh, well that would explain it. I was using it on the title screen. Is there a way I can define it earlier so I can use it on the title?
Theoretically you can modify the engine to define the variables earlier - the question is whether that would result in unwanted side effects.
The variables are defined on "new game" to make sure that they are set for to zero and defined for each game. Defining them earlier would make no sense and would rise the question on what values they have before they are even assigned to any gamestatus.

It might be usable for some specific variables that you want to be the same over all savefiles, but in that case any change in the engine would have to be compatible to any persistent variable script that you're using for that purpose.

And with that comment I would have to sign off - I don't know enough of those scripts to give any further tips.

Original thread: https://forums.rpgmakerweb.com/threads/cant-display-variables.122629/