Help - Search - Members - Calendar
Full Version: My tiny custom made script is being incompatible
RPG RPG Revolution Forums > Scripting > Script Development and Support
Titanhex
I made a tiny little script to run my minigame system. I needed to save the variables used for best compatibility, but the next thing I knew, it didn't want to be compatible with Requiem ABS.

It's a really small code though, and I aliased for optimum compatibility. :\ (Though I don't full understand aliasing yet) I did try putting my code both below and above Vampyr SBABS though.

So I'm hoping someone could tell me why it's not working! Thanks for the support :3

CODE
#==============================================================================
# ** Interpreter
#------------------------------------------------------------------------------
#  This interpreter runs event commands. This class is used within the
#  Game_System class and the Game_Event class.
#==============================================================================

class Game_Interpreter
  #--------------------------------------------------------------------------
  # * Event ID
  #--------------------------------------------------------------------------
  def ev_id
    # Returns event id
    return @event_id
  end
end

#==============================================================================
# ** Scene_File
#------------------------------------------------------------------------------
#  This class performs the save and load screen processing.
#==============================================================================

class Scene_File
  
  alias oldWriteSaveMGSys write_save_data
  def write_save_data(file)
    oldWriteSaveMGSys(file)
    Marshal.dump($util,              file)
    Marshal.dump($mgval,             file)
    Marshal.dump($mgtype,            file)
    Marshal.dump($mgquit,            file)
    Marshal.dump($mganim,            file)
  end

  alias oldReadSaveMGSys read_save_data
  def read_save_data(file)
    oldReadSaveMGSys(file)
    $util             = Marshal.load(file)
    $mgval            = Marshal.load(file)
    $mgval            = Marshal.load(file)
    $mgtype           = Marshal.load(file)
    $mgquit           = Marshal.load(file)
    $mganim           = Marshal.load(file)
  end

end

class Scene_Title

  alias oldNewGameMGSys command_new_game
  def command_new_game
    oldNewGameMGSys
    $util = Utility.new
    $mgval = []
    $mgtype = []
    $mgquit = []
    for i in 0..100
      $mgval[i] = 0
      $mgtype[i] = 0
    end
  end

end


Similar parts in the Vampyr SBABS code:

Scene File
CODE
#------------------------------------------------------------------------------
# Scene File
#------------------------------------------------------------------------------
class Scene_File < Scene_Base

  alias vampyr_sbabs_sfile_do_load do_load
  alias vampyr_sbabs_sfile_write_save_data write_save_data
  alias vampyr_sbabs_sfile_read_save_data read_save_data
  
  def do_load
    vampyr_sbabs_sfile_do_load
    $game_player.refresh
    for ally in $game_allies.compact
      ally.refresh
    end
  end
  
  def write_save_data(file)
    vampyr_sbabs_sfile_write_save_data(file)
    Marshal.dump($game_monsters, file)
    Marshal.dump($game_allies,   file)
    Marshal.dump($game_range,    file)
    Marshal.dump($game_drop,     file)
    Marshal.dump($game_bomb,     file)
  end
  
  def read_save_data(file)
    vampyr_sbabs_sfile_read_save_data(file)
    $game_monsters = Marshal.load(file)
    $game_allies   = Marshal.load(file)
    $game_range    = Marshal.load(file)
    $game_drop     = Marshal.load(file)
    $game_bomb     = Marshal.load(file)
  end
  
end


Scene_Title
CODE
class Scene_Title < Scene_Base
  
  alias vampyr_sbabs_scenetitle_create_game_objects create_game_objects
  alias vampyr_sbabs_scenetitle_command_new_game command_new_game
  
  def create_game_objects
    $game_monsters = []
    $game_allies = []
    $game_range = []
    $game_drop = []
    $game_bomb = []
    vampyr_sbabs_scenetitle_create_game_objects
    $Vampyr_SBABS = Vampyr_SBABS.new
  end
  
  def command_new_game
    vampyr_sbabs_scenetitle_command_new_game
    for ally in $game_allies.compact
      ally.map_id = $data_system.start_map_id
      ally.moveto($data_system.start_x, $data_system.start_y)
      ally.move_random
    end
  end
  
end
Night5h4d3
Aliasing is relatively simple, say I have a cat, and I name him fred, then someone else comes along and nick-names him freddie, his original name is fred, but now he has a nickname freddie and I can call him by both. However, freddie is a nickname and is not the real name of my cat, so you can't nickname freddie. In Ruby's terms, you can't alias a def more than once.

You'd need a compatibility rewrite that implemented the two but only had 1 alias.

These should work:
spoiler

This part is fine:

CODE
#==============================================================================
# ** Interpreter
#------------------------------------------------------------------------------
#  This interpreter runs event commands. This class is used within the
#  Game_System class and the Game_Event class.
#==============================================================================

class Game_Interpreter
  #--------------------------------------------------------------------------
  # * Event ID
  #--------------------------------------------------------------------------
  def ev_id
    # Returns event id
    return @event_id
  end
end

Replace Vampyr Scene_Title with:
CODE
class Scene_Title < Scene_Base
  
  alias vampyr_sbabs_scenetitle_create_game_objects create_game_objects
  alias vampyr_sbabs_scenetitle_command_new_game command_new_game
  
  def create_game_objects
    $game_monsters = []
    $game_allies = []
    $game_range = []
    $game_drop = []
    $game_bomb = []
    vampyr_sbabs_scenetitle_create_game_objects
    $Vampyr_SBABS = Vampyr_SBABS.new
    $util = Utility.new
    $mgval = []
    $mgtype = []
    $mgquit = []
    for i in 0..100
      $mgval[i] = 0
      $mgtype[i] = 0
    end
  end
  
  def command_new_game
    vampyr_sbabs_scenetitle_command_new_game
    for ally in $game_allies.compact
      ally.map_id = $data_system.start_map_id
      ally.moveto($data_system.start_x, $data_system.start_y)
      ally.move_random
    end
  end
  
end

Replace Vampyr Scene_File with:
CODE
#------------------------------------------------------------------------------
# Scene File
#------------------------------------------------------------------------------
class Scene_File < Scene_Base

  alias vampyr_sbabs_sfile_do_load do_load
  alias vampyr_sbabs_sfile_write_save_data write_save_data
  alias vampyr_sbabs_sfile_read_save_data read_save_data
  
  def do_load
    vampyr_sbabs_sfile_do_load
    $game_player.refresh
    for ally in $game_allies.compact
      ally.refresh
    end
  end
  
  def write_save_data(file)
    vampyr_sbabs_sfile_write_save_data(file)
    Marshal.dump($util,              file)
    Marshal.dump($mgval,             file)
    Marshal.dump($mgtype,            file)
    Marshal.dump($mgquit,            file)
    Marshal.dump($mganim,            file)
    Marshal.dump($game_monsters, file)
    Marshal.dump($game_allies,   file)
    Marshal.dump($game_range,    file)
    Marshal.dump($game_drop,     file)
    Marshal.dump($game_bomb,     file)
  end
  
  def read_save_data(file)
    vampyr_sbabs_sfile_read_save_data(file)
    $util             = Marshal.load(file)
    $mgval            = Marshal.load(file)
    $mgval            = Marshal.load(file)
    $mgtype           = Marshal.load(file)
    $mgquit           = Marshal.load(file)
    $mganim           = Marshal.load(file)
    $game_monsters = Marshal.load(file)
    $game_allies   = Marshal.load(file)
    $game_range    = Marshal.load(file)
    $game_drop     = Marshal.load(file)
    $game_bomb     = Marshal.load(file)
  end
  
end

Titanhex
I see. Didn't know you couldn't alias a def more than once.

But there's a problem, when I modify the script this way, I get the same error I've been running when trying to load a newly saved game:

Script 'Vampyr SBABS' line 4858: EOFError occured.

End of file reached.

I save, hit F12, and try to load and this error pops up. This is even when I put the edit mentioned RIGHT into the SBABS demo. (I suggest omitting the line $util = Utility.new so you can go on without a Util class.)

Here is the link to the demo right from the RMRK website: http://rmrk.net/index.php?action=dlattach;....0;attach=21879

If you make this edit, it should give you the error.

So, what would cause this? I wouldn't think it's script order, since the only system is the SBABS.
Night5h4d3
You have
"$mgval = Marshal.load(file)" twice, and I copied and pasted from your script so mine has it twice.
Titanhex
Ah thanks! I was overthinking what could have been the problem with the script edit. I went to bed after posting and was gonna wake up and check my code.

What's odd is the original file I stored this system in doesn't have a double $mgval. Wonder where it could have come from.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.