Problem with checking variables in different classes

I made a script that modifies scene_gameover and adds two commands to it called "continue" and "end game", the script worked out the way I had hoped it would: whenever I died, I would just choose "continue" the game would automatically load my most recent save file.

Up until yesterday, I found a problem with my script. I started a new game and died (without saving) and saw that my continue was selectable... so I chose that command and found out it took me back to my old saved game that I was playing before. I needed to find a way to disable the continue when a new game is started and re-enable the command when a game is saved.

My (failed) solution was to try and make the scene_gameover start method check whether "@can_continue" is == true / false. depending on that variable, it would either enable / disable the command for continue... but I just can't get anything to work... I tried but no luck, I keep getting errors like uninitialized etc.

Does anyone know how I could check whether a variable is true or not from different classes? If not, is there any alternate way to solve this problem? any help is greatly appreciated

EDIT: Here is the script

EDIT: Oh, the script was lacking an "end".. sorry (fixed)

Spoiler
#==============================================================================

# ** Window_TitleCommand

#------------------------------------------------------------------------------

#  This window is for selecting New Game/Continue on the title screen.

#==============================================================================

class Window_GameOver < Window_Command

 

  def initialize

    super(0, 0)

    update_placement

    select_symbol🙂continue) if save_file_exists

    self.openness = 0

    open

  end

  

  def update_placement

    self.x = (Graphics.width - width) / 2

    self.y = (Graphics.height * 1.6 - height) / 2

  end

 

  def window_width

    return 160

  end

 

  def make_command_list

    add_command("Continue", :continue, save_file_exists)

    add_command("End Game", :end_game)

  end

 

  def save_file_exists

    DataManager.save_file_exists?

  end

end

#==============================================================================

# ** Scene_Gameover

#------------------------------------------------------------------------------

#  This class performs game over screen processing.

#==============================================================================

 

class Scene_Gameover < Scene_Base

 

  def start

    super

    play_gameover_music

    fadeout_frozen_graphics

    create_background

    create_command_window

  end

 

  def create_command_window

    @command_window = Window_GameOver.new

    @command_window.set_handler🙂continue, method🙂command_continue))

    @command_window.set_handler🙂end_game, method🙂command_end_game))

  end

 

  def command_continue

    @index = DataManager.latest_savefile_index

    DataManager.load_game(@index)

    on_load_success

  end

 

  def on_load_success

    Sound.play_load

    fadeout_all

    $game_system.on_after_load

    SceneManager.goto(Scene_Map)

  end

  

  def command_end_game

    SceneManager.goto(Scene_Title)

  end

 

  def close_command_window

    @command_window.close

    update until @command_window.close?

  end

 

  def update

    super

  end

 

  def play_gameover_music

    RPG::BGM.stop

    RPG::BGS.stop

    Audio.bgm_play('Audio/BGM/' + "Dungeon1", 100, 100)

  end

 

  def create_background

    @sprite = Sprite.new

    @sprite.bitmap = Cache.system("GameOver")

  end

end
Just delete the saved files when a new game is started, so there's nothing to continue from?


Of course that means only one person could play your game at a time on a shared computer. If there were several people wanting to play on the same machine, each one would have to wait until the previous person has finished your game.
Does anyone know how I could check whether a variable is true or not from different classes? If not, is there any alternate way to solve this problem? any help is greatly appreciated
uhm, use a global variable instead of the class based one? or try ClassName.variable... not sure if that works though...
I would just create a new variable in DataManager or something that indicates the "last save file" for the current session. This is not the same as the "latest_save_file_index" which defaults to 0, which is not what you want.


When you start a new game, you would just set it to -1 or something to indicate that there's no "last save file".


Whenever you save or load, you would set it to the appropriate index, so this wouldn't interfere with other saves.
I finally got the script to disable (and properly load) after tinkering a while of testing and stuff! Turns out that I needed to know about how to use global variables. After making my global variable $can_continue = 0, 1, 2... I made the "continue" command make a specific code run depending on my global variables number

Thanks everyone for the help =]
This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/problem-with-checking-variables-in-different-classes.18498/