- 24
- Posts
- 6
- Years
- Seen Jul 24, 2023
Hello all,
I've been working for some time on a relatively small and simple skill tree for the player character. Eventually, I'd like to post it here when all of the kinks are worked out. I've gone through Marin's intro to ruby document, Luka's videos, and have been reading scripting questions on here for a while too, but this is my first time really trying to script something myself.
It works like so:
- there is a global variable ($skillpoints) that accounts for the amount of skill points the trainer has. There is a method pbAddSkillPoint that simply adds 1 to the $skillpoints variable
- Each skill (21 in total) is tied to a global variable ($trskill1, $trskill2) that is initially set to false at the beginning of my script. When the player selects a skill on my skill screen scene under the right conditions, the global variable for that skill is then set to true. I have edited various other scripts to work differently if a skill is true. For example, the Capture Specialist skill adds +10% to the catch rate when catching Pokemon if it is on. I used an if statement at the end of def pbThrowPokeball in PokeBattle_Battle to achieve this:
The snag that I've run into is that I have no idea how to get these variables to save. Everything works perfectly within the instance of the game that they're chosen in, but once I save and come back, $skillpoints is set back to 0 and all $trskillX are set back to false. I did some research and have tried moving my initial instances of the variables to a class that gets saved (Game_Player), but that didn't do it, and helped me to realize I don't really understand how the saving works. I have also tried adding lines to PScreen_Save ('Marshal.dump($skillpoints,f)' under def pbSave) and Pscreen_Load ('$skillpoints = Marshal.load(f)' under the File.open(savefile){|f| section), but all that does it crash the game when I try to load the save (including if I start over with a new save).
I hope this all made sense, and if anyone could point me in the right direction about saving and loading variables, I'd really appreciate it. There's still a ton about scripting/coding that I don't understand, so I'm pretty sure I'm making a novice mistake somewhere. Let me know if I need to provide more information or get more specific about anything, and I'll be happy to.
Edit: I just thought about setting the variables to be game variables/game switches. Would that be a better way to go about this? Would it hinder the eventual plug'n'play-ability of this script?
I've been working for some time on a relatively small and simple skill tree for the player character. Eventually, I'd like to post it here when all of the kinks are worked out. I've gone through Marin's intro to ruby document, Luka's videos, and have been reading scripting questions on here for a while too, but this is my first time really trying to script something myself.
It works like so:
- there is a global variable ($skillpoints) that accounts for the amount of skill points the trainer has. There is a method pbAddSkillPoint that simply adds 1 to the $skillpoints variable
- Each skill (21 in total) is tied to a global variable ($trskill1, $trskill2) that is initially set to false at the beginning of my script. When the player selects a skill on my skill screen scene under the right conditions, the global variable for that skill is then set to true. I have edited various other scripts to work differently if a skill is true. For example, the Capture Specialist skill adds +10% to the catch rate when catching Pokemon if it is on. I used an if statement at the end of def pbThrowPokeball in PokeBattle_Battle to achieve this:
Code:
if $tamerskill1 == true
x=(x*1.1).floor
end
The snag that I've run into is that I have no idea how to get these variables to save. Everything works perfectly within the instance of the game that they're chosen in, but once I save and come back, $skillpoints is set back to 0 and all $trskillX are set back to false. I did some research and have tried moving my initial instances of the variables to a class that gets saved (Game_Player), but that didn't do it, and helped me to realize I don't really understand how the saving works. I have also tried adding lines to PScreen_Save ('Marshal.dump($skillpoints,f)' under def pbSave) and Pscreen_Load ('$skillpoints = Marshal.load(f)' under the File.open(savefile){|f| section), but all that does it crash the game when I try to load the save (including if I start over with a new save).
I hope this all made sense, and if anyone could point me in the right direction about saving and loading variables, I'd really appreciate it. There's still a ton about scripting/coding that I don't understand, so I'm pretty sure I'm making a novice mistake somewhere. Let me know if I need to provide more information or get more specific about anything, and I'll be happy to.
Edit: I just thought about setting the variables to be game variables/game switches. Would that be a better way to go about this? Would it hinder the eventual plug'n'play-ability of this script?
Last edited: