• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

Change variables before loading game.

I-Like-Shiny-Pichu

ClariS <3
382
Posts
14
Years
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
 

venom12

Pokemon Crystal Rain Relased
476
Posts
17
Years
  • Age 33
  • Seen Dec 28, 2023
So you need to search def pbTryLoadFile(savefile) in pokemonload

and add
$game_switches=Marshal.load(f)
$game_variables=Marshal.load(f)
 

I-Like-Shiny-Pichu

ClariS <3
382
Posts
14
Years
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'

Main:15:in `mainFunction'

Main:15:in `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...
 
Last edited:

IceGod64

In the Lost & Found bin!
624
Posts
15
Years
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.
 

I-Like-Shiny-Pichu

ClariS <3
382
Posts
14
Years
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.
 

Rai Rai

Master of everything!
262
Posts
13
Years
  • Seen Aug 29, 2012
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
 

I-Like-Shiny-Pichu

ClariS <3
382
Posts
14
Years
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?
 

Rai Rai

Master of everything!
262
Posts
13
Years
  • Seen Aug 29, 2012
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
 
Last edited:

I-Like-Shiny-Pichu

ClariS <3
382
Posts
14
Years
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
 

Rai Rai

Master of everything!
262
Posts
13
Years
  • Seen Aug 29, 2012
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.
 
Last edited:

I-Like-Shiny-Pichu

ClariS <3
382
Posts
14
Years
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.
 

Maruno

Lead Dev of Pokémon Essentials
5,285
Posts
16
Years
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.
 

I-Like-Shiny-Pichu

ClariS <3
382
Posts
14
Years
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.
 

Maruno

Lead Dev of Pokémon Essentials
5,285
Posts
16
Years
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.
 

I-Like-Shiny-Pichu

ClariS <3
382
Posts
14
Years
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.
 
Last edited:
Back
Top