return_scene

O.k. so my CAT script is giving me some problems refreshing. If you start a new game, then try to go back or choose to continue from the title menu, and then cancel, it does not actually reinitialize the scene.

What I am trying to do reinitialize the scene all together. (i.e. make a brand new one)

I've tried "goto" and "call" both with no luck. I'm I just missing something. When I alias it, then check it, isn't the one I am checking the one it's going to go to. If so Why is this not starting the scene completely over.
 

Code:
#==============================================================================# ** Scene_Base#------------------------------------------------------------------------------#  This is a super class of all scenes within the game.#==============================================================================class Scene_Base  #--------------------------------------------------------------------------  # * Aliasing Method:  Return to Calling Scene  #--------------------------------------------------------------------------  alias :sbrs24520400005 :return_scene  #--------------------------------------------------------------------------  # * Return to Calling Scene  #--------------------------------------------------------------------------  def return_scene    sbrs24520400005()    if SceneManager.scene_is?(Scene_Title)      SceneManager.clear      SceneManager.goto(Scene_Title)    end  end  end #<--- End Class============================================================
return_scene, by default, is entirely coded to do SceneManager.return, which will exit processing right there and go back to the last scene in the stack. Your aliased code runs before your checking code. The alias calls return_scene, and since it's run before you check, it will simply call SceneManager.return. Move the alias to after your check:

Code:
  def return_scene    if SceneManager.scene_is?(Scene_Title)      SceneManager.clear      SceneManager.goto(Scene_Title)    else      sbrs24520400005()    end  end
ok but then it whould check the scene that I am exiting out of right. ie the menu and/or load scenes.
 

Edit* Still no luck.

Code:
#==============================================================================# ** SceneManager#------------------------------------------------------------------------------#  This module manages scene transitions. For example, it can handle# hierarchical structures such as calling the item screen from the main menu# or returning from the item screen to the main menu.#==============================================================================module SceneManager  #--------------------------------------------------------------------------  # * Clear Call Stack  #--------------------------------------------------------------------------  def self.returning_scene    return @stack[(@stack.size - 1)]  end end #<--- End Module===========================================================#==============================================================================# ** Scene_Base#------------------------------------------------------------------------------#  This is a super class of all scenes within the game.#==============================================================================class Scene_Base  #--------------------------------------------------------------------------  # * Aliasing Method:  Return to Calling Scene  #--------------------------------------------------------------------------  alias :sbrs24520400005 :return_scene  #--------------------------------------------------------------------------  # * Return to Calling Scene  #--------------------------------------------------------------------------  def return_scene    if SceneManager.returning_scene.instance_of?(Scene_Title)      SceneManager.clear      SceneManager.call(Scene_Title)    else      sbrs24520400005()    end  end end #<--- End Class============================================================
How are you getting bat to Scene_Title? F12 doesn't go back, it dumps the current stack and starts it over, so this would not run in that case (F12 would skip this entirely, actually)
If you start a new game, then try to go back via end game and when you choose to continue from the title menu then hit cancel it does the same thing.
Instead of trying to force Scene_Title to reinitialize, you should not rely in the initialize method at all in dealing with Scenes. You should be able to control whatever data creation/destruction you need to within the scene's start, post_start, pre_teriminate, and terminate methods, which are all run whether or not the scene is a 'new' instance when it starts. Unless you are hijacking the creation of Scene_Title itself to conditionally spit out another object completely?


The last script posted does succeed in creating a new instance of Scene_Title even if you cancel out of it from the load savefile screen (getting there from Scene_End uses goto, so would have already been creating a new instance from here anyway), so your issue is probably elsewhere.
Leaving out some of the frame updates, here is the meat of the script. I'm still not sure what's going on. Here is a link to the current demo if anyone wants to take a look.

Spoiler
Code:
#==============================================================================# ** Scene_Title#------------------------------------------------------------------------------#  This class performs the title screen processing.#==============================================================================class Scene_Title < Scene_Base   #--------------------------------------------------------------------------  # * Include Module  #--------------------------------------------------------------------------  include V_Custom_Animated_Title_Scene::Specs  #--------------------------------------------------------------------------  # * Start Processing  #--------------------------------------------------------------------------  def start    play_intro_movie(Movie_Name) if Play_Splash_Movie && Play_On_New_Game != true    create_command_window    init_cat_vars    play_title_music  end   #--------------------------------------------------------------------------  # * Aliasing Method: Create Command Window  #--------------------------------------------------------------------------  alias :ccw546345313131 :create_command_window  #--------------------------------------------------------------------------  # * Create Command Window  #--------------------------------------------------------------------------  def create_command_window    ccw546345313131()    @active = true    Command_Window_Activate_Time > 0 ? @command_window.deactivate && @active = false : @active = true  end  #--------------------------------------------------------------------------  # * Initialization CAT Variables  #--------------------------------------------------------------------------  def init_cat_vars    init_basic_vars    init_layer_vars    init_layer_info_vars  end                              #--------------------------------------------------------------------------  # * Basic Variable Initialization  #--------------------------------------------------------------------------  def init_basic_vars    @command_timer = 0    $title = true    @hour = nil    @minute = nil    @layers = {}    @layers_info = {}  end                              #--------------------------------------------------------------------------  # * Layer Variable Initialization  #--------------------------------------------------------------------------  def init_layer_vars    Layers.each_key { |i|      @layers[i] = Sprite.new      @layers[i].bitmap = Cache.title1(i) unless Layers[i].has_key?(:max_variable_frames)      @layers[i].bitmap = Cache.title1(i + "_0") if Layers[i].has_key?(:max_variable_frames)      @layers[i].x = Command_Window_X if Layers[i][:x] == nil      @layers[i].y = Command_Window_Y if Layers[i][:y] == nil      @layers[i].x = Layers[i][:x] unless Layers[i][:x] == nil      @layers[i].y = Layers[i][:y] unless Layers[i][:y] == nil      @layers[i].z = Layers[i][:z]      @layers[i].ox = Layers[i][:ox]      @layers[i].oy = Layers[i][:oy]      @layers[i].opacity = Layers[i][:opacity]      @layers[i].angle = Layers[i][:angle] if Layers[i].has_key?(:angle)      @layers[i].blend = Layers[i][:blend] if Layers[i].has_key?(:blend)    }  end                              #--------------------------------------------------------------------------  # * Layer Info Variable Initialization  #--------------------------------------------------------------------------  def init_layer_info_vars    Layers.each_key { |i|      @layers_info[i] = {           :animation_types => Layers[i][:animation_types],        :rotation_frame => 0,        :scroll_frame => 0,        :fade_frame => 0,        :fade_out_frame => 0,        :fade_out_time => 0,        :wave_frame => 0,        :blend_frame => 0,        :variable_frame => 0,        :variable_id => 0,        :initialize_rotation_frame => 0,        :initialize_move_frame => 0,        :initialize_fade_in_frame => 0,        :fade_switch => true,        :wave_switch => true,        :blend_switch => true,        :blend_switch => true,        :initialize_frame => 0,        :initialize_switch => true,      }      @layers_info[i][:rotation_speed] = Layers[i][:rotation_speed] if Layers[i].has_key?(:rotation_speed)      @layers_info[i][:scroll_speed] = Layers[i][:scroll_speed] if Layers[i].has_key?(:scroll_speed)      @layers_info[i][:fade_speed] = Layers[i][:fade_speed] if Layers[i].has_key?(:fade_speed)      @layers_info[i][:rotation_frame_rate] = Layers[i][:rotation_frame_rate] if Layers[i].has_key?(:rotation_frame_rate)      @layers_info[i][:scroll_frame_rate] = Layers[i][:scroll_frame_rate] if Layers[i].has_key?(:scroll_frame_rate)      @layers_info[i][:fade_frame_rate] = Layers[i][:fade_frame_rate] if Layers[i].has_key?(:fade_frame_rate)      @layers_info[i][:start_fade_out] = Layers[i][:start_fade_out] if Layers[i].has_key?(:start_fade_out)      @layers_info[i][:fade_out_frame_rate] = Layers[i][:fade_out_frame_rate] if Layers[i].has_key?(:fade_out_frame_rate)      @layers_info[i][:fade_out_speed] = Layers[i][:fade_out_speed] if Layers[i].has_key?(:fade_out_speed)      @layers_info[i][:fade_max_opacity] = Layers[i][:fade_max_opacity] if Layers[i].has_key?(:fade_max_opacity)      @layers_info[i][:fade_min_opacity] = Layers[i][:fade_min_opacity] if Layers[i].has_key?(:fade_min_opacity)      @layers_info[i][:wave_frame_rate] = Layers[i][:wave_frame_rate] if Layers[i].has_key?(:wave_frame_rate)      @layers_info[i][:wave_strength] = Layers[i][:wave_strength] if Layers[i].has_key?(:wave_frame_rate)      @layers_info[i][:blend_frame_rate] = Layers[i][:blend_frame_rate] if Layers[i].has_key?(:blend_frame_rate)      @layers_info[i][:variable_frame_rate] = Layers[i][:variable_frame_rate] if Layers[i].has_key?(:variable_frame_rate)      @layers_info[i][:max_variable_frames] = Layers[i][:max_variable_frames] if Layers[i].has_key?(:max_variable_frames)      @layers_info[i][:variable_frame_name] = (i + "_" + @layers_info[i][:variable_id].to_s) if Layers[i].has_key?(:max_variable_frames)      @layers_info[i][:initialize_time] = Layers[i][:initialize_time] if Layers[i].has_key?(:initialize_time)      @layers_info[i][:initialize_time] = 0 if Layers[i].has_key?(:initialize_time) == false      @layers_info[i][:initialize_animations] = Layers[i][:initialize_animations] if Layers[i].has_key?(:initialize_animations)      @layers_info[i][:initialize_animations] = [0] if Layers[i].has_key?(:initialize_animations) == false      @layers_info[i][:initialize_rotation_frame_rate] = Layers[i][:initialize_rotation_frame_rate] if Layers[i].has_key?(:initialize_rotation_frame_rate)      @layers_info[i][:initialize_rotation_speed] = Layers[i][:initialize_rotation_speed] if Layers[i].has_key?(:initialize_rotation_speed)      @layers_info[i][:initialize_rotation_final_angle] = Layers[i][:initialize_rotation_final_angle] if Layers[i].has_key?(:initialize_rotation_final_angle)      @layers_info[i][:initialize_move_frame_rate] = Layers[i][:initialize_move_frame_rate] if Layers[i].has_key?(:initialize_move_frame_rate)      @layers_info[i][:initialize_move_speed] = Layers[i][:initialize_move_speed] if Layers[i].has_key?(:initialize_move_speed)      @layers_info[i][:initialize_move_final_x] = Layers[i][:initialize_move_final_x] if Layers[i].has_key?(:initialize_move_final_x)      @layers_info[i][:initialize_move_final_y] = Layers[i][:initialize_move_final_y] if Layers[i].has_key?(:initialize_move_final_y)      @layers_info[i][:initialize_fade_in_frame_rate] = Layers[i][:initialize_fade_in_frame_rate] if Layers[i].has_key?(:initialize_fade_in_frame_rate)      @layers_info[i][:initialize_fade_in_speed] = Layers[i][:initialize_fade_in_speed] if Layers[i].has_key?(:initialize_fade_in_speed)    }  end                              #--------------------------------------------------------------------------  # * Reset Layers  #--------------------------------------------------------------------------  def reset_layers    terminate    start    $game_system.reset_title = false  end   #--------------------------------------------------------------------------  # * Termination Processing  #--------------------------------------------------------------------------  def terminate    Graphics.freeze    dispose_all_windows    SceneManager.snapshot_for_background    dispose_cat_layers    dispose_cat_layers_info  end   #--------------------------------------------------------------------------  # * Clear Layer Info Variable  #--------------------------------------------------------------------------  def dispose_cat_layers_info    @layers_info.clear  end   #--------------------------------------------------------------------------  # * Dipose Layers  #--------------------------------------------------------------------------  def dispose_cat_layers    @layers.each_key { |i|      @layers[i].bitmap.dispose      @layers[i].dispose    }    @layers.clear  end   #--------------------------------------------------------------------------  # * Aliasing Method: Update Processing  #--------------------------------------------------------------------------  alias :u546131651321 :update  #--------------------------------------------------------------------------  # * Update Processing  #--------------------------------------------------------------------------  def update    command_update if Command_Window_Activate_Time > 0 && @active == false    animate_layers if @layers    reset_layers if $game_system.reset_title == true    u546131651321()  endend #==============================================================================# ** SceneManager#------------------------------------------------------------------------------#  This module manages scene transitions. For example, it can handle# hierarchical structures such as calling the item screen from the main menu# or returning from the item screen to the main menu.#==============================================================================module SceneManager  #--------------------------------------------------------------------------  # * Aliasing Module Method: Direct Transition, Call, and Return to Caller  #--------------------------------------------------------------------------  class << self    alias :smgt6654313213210005 :goto    alias :smc453247527240005 :call    alias :smr7877877574555520005 :return  end   #--------------------------------------------------------------------------  # * Direct Transition  #--------------------------------------------------------------------------  def self.goto(scene_class)    smgt6654313213210005(scene_class)    $game_system.reset_title = true  if @scene.instance_of?(Scene_Title)  end   #--------------------------------------------------------------------------  # * Call  #--------------------------------------------------------------------------  def self.call(scene_class)    smc453247527240005(scene_class)    $game_system.reset_title = true  if @scene.instance_of?(Scene_Title)  end   #--------------------------------------------------------------------------  # * Return to Caller  #--------------------------------------------------------------------------  def self.return    smr7877877574555520005()    $game_system.reset_title = true  if @scene.instance_of?(Scene_Title)  end end #<--- End Module=========================================================== 
What is the purpose of the reset_layers method? That seems to be breaking the script after you transition back onto title because it calls start and terminate (not needed, the scene goes through Scene_Base#main every time) and terminate freezes the Graphics which in turn makes it so you are stuck with the screen looking like the first frame of the animation. Is that the issue you are having?
Here is the script minus the reset methods(how it was before I tinkered with it) It is only affecting the "Title" and the three clock images.

Thanks again Mithran.
You are polluting your constant by passing arrays down without duping them, then modifying those same arrays later. The constants are hashes which also contain some arrays. The arrays are being directly passed into other hashes without duping.


I managed to trace the error to this line:

Code:
      @layers_info[i][:initialize_animations] = Layers[i][:initialize_animations] if Layers[i].has_key?(:initialize_animations)
Throw in a dup there so you aren't passing around the same array and you should be good:
Code:
      @layers_info[i][:initialize_animations] = Layers[i][:initialize_animations].dup if Layers[i].has_key?(:initialize_animations)
I saw another array passed down through the :animation_types key, but it didn't look like you modified this one so it should be safe. If not, just dup that one when you pass it down to @layers_info, too.
Thank You, Thank You, Thank You. It's fixed!!! And without a ton of code.(.dup... I was so close.)  Awhile back Shaz, Adiktuzmiko, Napoleon, and a few others tried they're hardest to teach me the value of this. I think that this was a prime example of what they where trying to say. Thanks again Everyone.
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/return_scene.21909/