Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Bonus Section

I have attempted to make a bonus section for my game, and the whole thing works by loading a game file. The idea is that the further you progress in the game, the more bonuses are in the bonus room.

The objects that appear are based off switches and variables that are changed in the main game.

Here's the code I tried to make. I'm no scriptor, and so I just tried this;
Code:
#==============================================================================
# ** Scene_Load
#------------------------------------------------------------------------------
#  This class performs load screen processing.
#==============================================================================

class Scene_BonusLoad < Scene_File
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    # Remake temporary object
    $game_temp = Game_Temp.new
    # Timestamp selects new file
    $game_temp.last_file_index = 0
    latest_time = Time.at(0)
    for i in 0..3
      filename = make_filename(i)
      if FileTest.exist?(filename)
        file = File.open(filename, "r")
        if file.mtime > latest_time
          latest_time = file.mtimea
          $game_temp.last_file_index = i
        end
        file.close
      end
    end
    super("Which file would you like to load?")
  end
  #--------------------------------------------------------------------------
  # * Decision Processing
  #--------------------------------------------------------------------------
  def on_decision(filename)
    # If file doesn't exist
    unless FileTest.exist?(filename)
      # Play buzzer SE
      $game_system.se_play($data_system.buzzer_se)
      return
    end
    # Play load SE
    $game_system.se_play($data_system.load_se)
    # Read save data
    file = File.open(filename, "rb")
    read_save_data(file)
    file.close
    # Restore BGM and BGS
    $game_system.bgm_play($game_system.playing_bgm)
    $game_system.bgs_play($game_system.playing_bgs)
    # Update map (run parallel process event)
    $game_map.update
    # Switch to map screen
    $scene = Scene_Map.new

  end
  #--------------------------------------------------------------------------
  # * Cancel Processing
  #--------------------------------------------------------------------------
  def on_cancel
    # Play cancel SE
    $game_system.se_play($data_system.cancel_se)
    # Switch to title screen
    $scene = Scene_Title.new
    $game_map.setup(3)
    $game_player.center(0,0)
  end
  #--------------------------------------------------------------------------
  # * Read Save Data
  #     file : file object for reading (opened)
  #--------------------------------------------------------------------------
  def read_save_data(file)
    # Read character data for drawing save file
    characters = Marshal.load(file)
    # Read frame count for measuring play time
    Graphics.frame_count = Marshal.load(file)
    # Read each type of game object
    $game_system        = Marshal.load(file)
    $game_switches      = Marshal.load(file)
    $game_variables     = Marshal.load(file)
    $game_self_switches = Marshal.load(file)
    $game_screen        = Marshal.load(file)
    $game_actors        = Marshal.load(file)
    $game_party         = Marshal.load(file)
    $game_troop         = Marshal.load(file)
    $game_map           = Marshal.load(file)
    $game_player        = Marshal.load(file)
    # If magic number is different from when saving
    # (if editing was added with editor)
    if $game_system.magic_number != $data_system.magic_number
      # Load map
      $game_map.setup(3)
      $game_player.center(0,0)
    end
    # Refresh party members
    $game_party.refresh
  end
end
Here's the problem.

Although, I inserted code to take the player to the correct map, it still takes me to the main game. However, I have found that this code works perfectly if I go into the editor and try again.

I'd love for someone to please help me with this.

Thnaks. :)
 
You can't set $game_map = 3.  Put it back to Marshal.load(file)
If you want to see what data is in $game_map put
p $game_map
after the load statement.  (lots of data)

I think that should do it.

Be Well
 
That was just to illustrate why you can't just set $game_map = 3.
Code:
    $game_map           = Marshal.load(file)
    p $game_map
will show what data is supposed to be in $game_map

I'm still having a hard time understanding what you are trying to do.

You have an additional command in Scene_Title to call Scene_BonusLoad?

You want to load one of the users save files, then transfer the player to MAP3 instead of Scene_Title?

Help me out here....  :scruff:

Be Well
 
Okay, sorry.

I want the player to be able to load a game. BUT instead of taking it to where they last saved, I want them to go to Map003.

The idea is that they will go to this map with all their switches and vairables the same. The items in the bonus room are dependant on variables changed in-game.

Thanks
 
I never said anything about the title screen. I can get it to get tot this script.

What I want this script to do is when the player selects their file, it does not take them to their last location, but instead to map003.

What happens with thsi script is that this does not happen, and I don't know why. What does happen is the player goes to their last location.

Can someone please debug this script or write one that takes the player to map003 when their file is loaded. Thanks very much.
 
Ok, I still don't understand when/why you're going to the bonus room...

but the only thing currently wrong with that script is in line 22
"mtimea"  should be  "mtime"

I added this to a brand new test game, with no other custom scripts, and
modified Scene_Title to call "Scene_BonusLoad.new" instead of "Scene_Load.new"
I test, then save on map001.  Go back to "continue", pick my save file, and it takes me to map003.

TTFN
 
comment out the "magic_number" bit, so it loads map 3 everytime...

Code:
    # If magic number is different from when saving
    # (if editing was added with editor)
    #if $game_system.magic_number != $data_system.magic_number
      # Load map
      $game_map.setup(3)
      $game_player.center(0,0)
    #end
    # Refresh party members
    $game_party.refresh
 
Brewmeister":bshur0rj said:
comment out the "magic_number" bit, so it loads map 3 everytime...

Code:
    # If magic number is different from when saving
    # (if editing was added with editor)
    #if $game_system.magic_number != $data_system.magic_number
      # Load map
      $game_map.setup(3)
      $game_player.center(0,0)
    #end
    # Refresh party members
    $game_party.refresh
Ooh, that doesnt work. I get this error;
http://i51.photobucket.com/albums/f359/ ... /error.png[/img]
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top