The PokéCommunity Forums Fan Games Game Development Pokémon Essentials
Change variables before loading game.

Pokémon Essentials All questions and discussion about Pokémon Essentials, the Pokémon game kit for RPG Maker XP, go in here. Also contains links to the latest downloads and the Essentials Wiki.

Reply
 
Thread Tools
  #1    
Old July 30th, 2012 (6:56 AM).
I-Like-Shiny-Pichu's Avatar
I-Like-Shiny-Pichu I-Like-Shiny-Pichu is offline
ClariS <3
     
    Join Date: Mar 2010
    Location: ANIMULAND
    Age: 21
    Gender: Female
    Nature: Naughty
    Posts: 373
    Hi, I am in the process of scripting a Mystery Gift system for the latest version of essentials. All appears to be working well, provided I search for gifts after the game has been loaded. However, if I try and search before the game is loaded I get errors, and I believe this is due to it accessing variables (and changing them). My question is, how can I access (and modify) variables in a save file before pressing "continue" on the load screen? (I have a Mystery Gift button there as well as the other options) If anyone could help ASAP that would be great. Thanks in advance
    __________________
    sukiyami.






    "I dreamt that you were a dog. And the dog was my husband. Anyway, it was the worst dream ever." — Aisaka Taiga
    Reply With Quote

    Relevant Advertising!

      #2    
    Old July 30th, 2012 (8:14 AM).
    venom12's Avatar
    venom12 venom12 is offline
    Pokemon Crystal Rain Relased
       
      Join Date: Sep 2006
      Age: 26
      Gender: Male
      Nature: Adamant
      Posts: 528
      Send a message via Windows Live Messenger to venom12
      So you need to search def pbTryLoadFile(savefile) in pokemonload

      and add
      $game_switches=Marshal.load(f)
      $game_variables=Marshal.load(f)
      Reply With Quote
        #3    
      Old July 30th, 2012 (8:29 AM). Edited July 30th, 2012 by I-Like-Shiny-Pichu.
      I-Like-Shiny-Pichu's Avatar
      I-Like-Shiny-Pichu I-Like-Shiny-Pichu is offline
      ClariS <3
         
        Join Date: Mar 2010
        Location: ANIMULAND
        Age: 21
        Gender: Female
        Nature: Naughty
        Posts: 373
        Thanks once again Venom12, though the game now seems to think the variables are set to something different than they should be (0). I'll try with a new save file and let you know if it works then.

        Edit: Just checked and the game still seems to think these variables are set to something other than 0, even though 0 is default. I'm not sure why since it works fine once the game has been loaded. Any ideas?

        Edit 2: Upon trying to find out what the variable was set to (by displaying it in a message) I got the following error:
        ---------------------------
        Pokemon Essentials
        ---------------------------
        Exception: TypeError

        Message: can't clone FalseClass

        PBIntl:654:in `clone'

        PBIntl:654:in `_INTL'

        MysteryGift:36:in `pbMysteryGiftSearch'

        PokemonLoad:645:in `pbStartLoadScreen'

        PokemonLoad:521:in `loop'

        PokemonLoad:647:in `pbStartLoadScreen'

        DebugIntro:6:in `main'

        Main:43:in `mainFunctionDebug'

        Mainin `mainFunction'

        Mainin `pbCriticalCode'



        This exception was logged in ./errorlog.txt.

        Press Ctrl+C to copy this message to the clipboard.
        ---------------------------
        OK
        ---------------------------

        The exact script I used works when displaying the wonder card message, so the script is not at fault. I'm not sure what is at fault though...
        __________________
        sukiyami.






        "I dreamt that you were a dog. And the dog was my husband. Anyway, it was the worst dream ever." — Aisaka Taiga
        Reply With Quote
          #4    
        Old July 30th, 2012 (9:00 AM).
        IceGod64's Avatar
        IceGod64 IceGod64 is offline
        In the Lost & Found bin!
           
          Join Date: Oct 2008
          Location: Castelia City
          Age: 29
          Gender: Male
          Nature: Naive
          Posts: 623
          When messing with the load scene, I recommend deleting your save file entirely. I.E, delete game.rxdata from C:\users\YOURNAME\saved games\

          I don't know if that's the solution in this particular case, but perhaps.
          __________________

          Reply With Quote
            #5    
          Old July 30th, 2012 (10:29 AM).
          I-Like-Shiny-Pichu's Avatar
          I-Like-Shiny-Pichu I-Like-Shiny-Pichu is offline
          ClariS <3
             
            Join Date: Mar 2010
            Location: ANIMULAND
            Age: 21
            Gender: Female
            Nature: Naughty
            Posts: 373
            I shall delete my save file and see if it works after that

            Edit: No, it still gives me the same error upon trying to display the contents of the variable.
            __________________
            sukiyami.






            "I dreamt that you were a dog. And the dog was my husband. Anyway, it was the worst dream ever." — Aisaka Taiga
            Reply With Quote
              #6    
            Old July 30th, 2012 (12:33 PM).
            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
              I shall delete my save file and see if it works after that

              Edit: No, it still gives me the same error upon trying to display the contents of the variable.
              Remove what venom12 said to add in pokemonload. If you're trying to access the game variables before the save file is loaded, then you will need to add in these two lines in the main script just under the line where it says $game_system = Game_System.new
              $game_variables = Game_Variables.new
              $game_switches = Game_Switches.new
              __________________
              Reply With Quote
                #7    
              Old July 30th, 2012 (1:14 PM).
              I-Like-Shiny-Pichu's Avatar
              I-Like-Shiny-Pichu I-Like-Shiny-Pichu is offline
              ClariS <3
                 
                Join Date: Mar 2010
                Location: ANIMULAND
                Age: 21
                Gender: Female
                Nature: Naughty
                Posts: 373
                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?
                __________________
                sukiyami.






                "I dreamt that you were a dog. And the dog was my husband. Anyway, it was the worst dream ever." — Aisaka Taiga
                Reply With Quote
                  #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
                    #9    
                  Old July 30th, 2012 (1:53 PM).
                  I-Like-Shiny-Pichu's Avatar
                  I-Like-Shiny-Pichu I-Like-Shiny-Pichu is offline
                  ClariS <3
                     
                    Join Date: Mar 2010
                    Location: ANIMULAND
                    Age: 21
                    Gender: Female
                    Nature: Naughty
                    Posts: 373
                    It is now giving me an error upon loading the game.."Cannot convert Game_Switches to integer". Any ideas what the problem is? Thanks so much for all your help so far, I can feel that we are very close to solving this
                    __________________
                    sukiyami.






                    "I dreamt that you were a dog. And the dog was my husband. Anyway, it was the worst dream ever." — Aisaka Taiga
                    Reply With Quote
                      #10    
                    Old July 30th, 2012 (2:06 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
                      It is now giving me an error upon loading the game.."Cannot convert Game_Switches to integer". Any ideas what the problem is? Thanks so much for all your help so far, I can feel that we are very close to solving this
                      I got a feeling it's because I made a little mistake on this part of the code:
                      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
                      Change this line File.open(RTP.getSaveFileName("Game.rxdata"),"wb"{|f| to File.open(RTP.getSaveFileName("Game.rxdata")),"wb"{|f|
                      I accidentally missed one bracket on the line XD. Hopefully that should fix it.

                      EDIT:
                      Ignore that, it seems the method for saving the file information is a bit different compared to what I was expecting. I'll add in a fix soon as I can.
                      __________________
                      Reply With Quote
                        #11    
                      Old July 30th, 2012 (2:09 PM).
                      I-Like-Shiny-Pichu's Avatar
                      I-Like-Shiny-Pichu I-Like-Shiny-Pichu is offline
                      ClariS <3
                         
                        Join Date: Mar 2010
                        Location: ANIMULAND
                        Age: 21
                        Gender: Female
                        Nature: Naughty
                        Posts: 373
                        No, I corrected that already (I realized you had made a typo). Upon deleting the now corrupted save file I noticed that it was only 1kb, which seems awfully small...maybe only part of the save file is being saved?

                        Edit: I replaced the commands you gave me with "pbSave" and it works..nearly...problem is, since it saves the map etc as well...it cannot load. I think I need to somehow edit just the variables line while keeping the rest of the save intact.
                        __________________
                        sukiyami.






                        "I dreamt that you were a dog. And the dog was my husband. Anyway, it was the worst dream ever." — Aisaka Taiga
                        Reply With Quote
                          #12    
                        Old July 31st, 2012 (4:22 AM).
                        Maruno's Avatar
                        Maruno Maruno is offline
                        Lead Dev of Pokémon Essentials
                           
                          Join Date: Jan 2008
                          Location: England
                          Posts: 5,173
                          So much dodgy advice...

                          The menu and game-loading all appear in the same method. What I would do is save the required data into a random unrelated variable (called sausage or something) when you use the Mystery Gift, and then after loading/starting a new game, add the MG data to whichever variables to need as you would normally (as if you were in the middle of a game).

                          There's no need to change when the save information is loaded. That's just too complicated for what you want to do.

                          I don't know what changes you've made to the code to incorporate the Mystery Gift function, so I can't be more specific. If you want directions, you can show us/me what you've done.
                          __________________
                          Go to the Pokémon Essentials Wiki

                          | Downloads | Tutorials | Fangames |
                          | All Animations Project |

                          Follow me on Twitter: @maruno42


                          Reply With Quote
                            #13    
                          Old July 31st, 2012 (6:34 AM).
                          I-Like-Shiny-Pichu's Avatar
                          I-Like-Shiny-Pichu I-Like-Shiny-Pichu is offline
                          ClariS <3
                             
                            Join Date: Mar 2010
                            Location: ANIMULAND
                            Age: 21
                            Gender: Female
                            Nature: Naughty
                            Posts: 373
                            All I've done to add the mystery gift currently is just replaced the options button (I don't want it there) with a button that calls the mystery gift script. I'm not entirely sure what you are telling me to do to be quite honest...As all the variables reset to what they were when the game was saved, I don't quite know how I can save all the information to a variable and then use that to set all the others. I could probably save all the information to a file and then load it from that when loading the game, but then the file is open to tampering (and I'm pretty sure there are people who would do that). Sorry for being such a pain, I'm quite new to scripting and learning as I go.
                            __________________
                            sukiyami.






                            "I dreamt that you were a dog. And the dog was my husband. Anyway, it was the worst dream ever." — Aisaka Taiga
                            Reply With Quote
                              #14    
                            Old July 31st, 2012 (8:01 AM).
                            Maruno's Avatar
                            Maruno Maruno is offline
                            Lead Dev of Pokémon Essentials
                               
                              Join Date: Jan 2008
                              Location: England
                              Posts: 5,173
                              The Mystery Gift script should return the information it gathered, rather than try to record it somewhere. That information can then hang around in the def pbStartLoadScreen until it has loaded the save/started a new game, and then you can add the Mystery Gift information to the appropriate variables.

                              It's hard to explain in an abstract manner (i.e. when you don't have the code itself to point at).

                              Alternatively, don't have the Mystery Gift there. Put it in the main game instead. It would be easier.
                              __________________
                              Go to the Pokémon Essentials Wiki

                              | Downloads | Tutorials | Fangames |
                              | All Animations Project |

                              Follow me on Twitter: @maruno42


                              Reply With Quote
                                #15    
                              Old July 31st, 2012 (9:12 AM). Edited August 2nd, 2012 by I-Like-Shiny-Pichu.
                              I-Like-Shiny-Pichu's Avatar
                              I-Like-Shiny-Pichu I-Like-Shiny-Pichu is offline
                              ClariS <3
                                 
                                Join Date: Mar 2010
                                Location: ANIMULAND
                                Age: 21
                                Gender: Female
                                Nature: Naughty
                                Posts: 373
                                If it will help, I can PM you the Mystery Gift script as it stands currently, its not yet complete as all it does is searches for the gift, checks if the player has the gift already etc.

                                Edit: This problem has now been solved via PM. This thread can now be closed if a mod wishes to do so.
                                __________________
                                sukiyami.






                                "I dreamt that you were a dog. And the dog was my husband. Anyway, it was the worst dream ever." — Aisaka Taiga
                                Reply With Quote
                                Reply
                                Quick Reply

                                Sponsored Links
                                Thread Tools

                                Posting Rules
                                You may not post new threads
                                You may not post replies
                                You may not post attachments
                                You may not edit your posts

                                BB code is On
                                Smilies are On
                                [IMG] code is On
                                HTML code is Off

                                Forum Jump


                                All times are GMT -8. The time now is 3:13 AM.