View Single Post
  #8    
Old July 30th, 2012 (1:35 PM). Edited July 30th, 2012 by Rai Rai.
Rai Rai's Avatar
Rai Rai Rai Rai is offline
Master of everything!
     
    Join Date: Aug 2010
    Gender: Male
    Posts: 267
    Quote:
    Originally Posted by I-Like-Shiny-Pichu View Post
    Thanks Rai Rai. It now (seems) to be loading the variables before the game is loaded. However, upon loading the game the variables are reset. Do I need to add something to my script so that this doesn't happen?
    Well, you could try open the save file, then dump the variable changes into it. Give me a few minutes and I'll post a reply with the commands you need.

    EDIT:

    Within the main script once more place the following code just after the snippet I gave you earlier.
    Code:
        savefile=RTP.getSaveFileName("Game.rxdata")
        if safeExists?(RTP.getSaveFileName("Game.rxdata"))
          File.open(savefile){|f|
              $Trainer             = Marshal.load(f)
              Graphics.frame_count = Marshal.load(f)
              $game_system         = Marshal.load(f)
              Marshal.load(f) # PokemonSystem already loaded
              Marshal.load(f) # Current map id no longer needed
              $game_switches       = Marshal.load(f)
              $game_variables      = Marshal.load(f)
              $game_self_switches  = Marshal.load(f)
              $game_screen         = Marshal.load(f)
              $MapFactory          = Marshal.load(f)
              $game_map            = $MapFactory.map
              $game_player         = Marshal.load(f)
              $PokemonGlobal       = Marshal.load(f)
              metadata             = Marshal.load(f)
              $ItemData            = readItemList("Data/items.dat")
              $PokemonBag          = Marshal.load(f)
              $PokemonStorage      = Marshal.load(f)
          }
        end
    That will load up everything before the game fully initializes the save file. To make it so that the game then keeps the changes I guess you would have to do something like the following in the section where your script is ending:

    Code:
        savefile=(RTP.getSaveFileName("Game.rxdata"))
        if safeExist?(savefile)
          File.open(RTP.getSaveFileName("Game.rxdata"),"wb"{|f|
             Marshal.dump($game_variables,f)
             Marshal.dump($game_switches,f)
          }
        end
    __________________
    Reply With Quote