Help with choices

Hello, I am trying to update the game saving so that when save is selected:
1) the menu closes
2) text appears asking "are you sure?" with choices "yes" or "no"
3) if player chooses yes, the game saves to the first file

What I've done is add a new command called save2 that lookos like this:
def command_save2 return_scene $game_message.add("Are you sure you want to save?") params = [] choices = [] choices.push("Yes") choices.push("No") params.push(choices) params.push(1) setup_choices(params) end

using this i get an error saying:
"undefined method 'setup_choices' for Scene_Menu"

if i replace setup_choices with the code that i want to be called, something like this:
def command_save2 return_scene $game_message.add("Are you sure you want to save?") params = [] choices = [] choices.push("Yes") choices.push("No") params.push(choices) params.push(1) params[0].each {|s| $game_message.choices.push(s) } $game_message.choice_cancel_type = params[1] $game_message.choice_proc = Proc.new {|n| @branch[@indent] = n } end

my choices actually appear, but when i choose one, i get an error saying:
"undefined method '[]=' for nil:NilClass"

I think this is the wrong way to go about it though, and that my issues stem from not being able to call setup_choices properly. Any help would be greatly appreciated 🙂
I managed to make a little progress. it now shows choices and there is no errors, but the save_game call fails.

def command_save2 return_scene $game_message.add("Are you sure you want to save?") params = [] choices = [] choices.push("Yes") choices.push("No") params.push(choices) params.push(0) params[0].each {|s| $game_message.choices.push(s) } $game_message.choice_cancel_type = params[1] $game_message.choice_proc = Proc.new {|n| case n when 0 if DataManager.save_game(0) on_save_success else Sound.play_buzzer end end } end
I don't fully understand it myself but the viewport was something that needed to be involved from what I could tell.
This is what I was able to put together to make it work.
Ruby:
class Scene_Menu < Scene_MenuBase
  alias r2_save_file2_command_window  create_command_window
  def create_command_window
    r2_save_file2_command_window
    @command_window.set_handler(:save,      method(:command_save2))
  end
  def command_save2
    $game_message.add("Are you sure you want to save?")
    params = [["Yes","No"], 0]
    params[0].each {|s| $game_message.choices.push(s) }
    $game_message.choice_cancel_type = params[1]
    $game_message.choice_proc = Proc.new {|n|
      case n
        when 0
          SceneManager.call(Scene_Save)
        end
    }
    return_scene
  end


class Scene_File < Scene_MenuBase
  def start
    super
    create_savefile_viewport
  end
  def terminate
    super
    @savefile_viewport.dispose
  end
  def update
    super
  end
  def create_savefile_viewport
    @savefile_viewport = Viewport.new
  end
end

class Scene_Load < Scene_File
  def start
    super
    on_savefile_ok
  end
  def on_savefile_ok
    super
    if DataManager.load_game(0)
      on_load_success
    else
      Sound.play_buzzer
    end
  end
end
 
class Scene_Save < Scene_File
  def start
    super
    on_savefile_ok
  end
  def on_savefile_ok
    super
    if DataManager.save_game(0)
      on_save_success
    else
      Sound.play_buzzer
    end
  end
end
Thanks you so much! it's a little confusing why the viewport needs to be involved, but after adding it to my own script it's working as expected.

Original thread: https://forums.rpgmakerweb.com/threads/help-with-choices.143943/