Game Custom Data v1.26

Update! You can now effectively save into the game folder if you want even if the user can modify where he places your game. 🙂
Updated to version 1.25


Version 1.25 - fixed a bug where it won't allow loading of save files if autosave is true
Hello, Adiktuzmiko.

I wanted to use your script in my current project ("Dragonblood") in order to save the ending obtained by the player (just in case I make a sequel).

However, when I want to playtest the game (and test the script at the same time), RGSS3 says:

Script 'GameCustomData' line 219: SyntaxError occured.unexpected $end, expecting keyword_endStrange, because I read the script and found no missing equivalent to a 'begin' (sorry, I'm not into Ruby that much, I prefer C++).

Deleting the last 'end' gives another error, and adding one does too.

Thanks in advance for your answer.
Did you edit the script? If yes, which parts? Also, if yes, please try to use an unedited version and see if the error still happens
Did you edit the script? If yes, which parts? Also, if yes, please try to use an unedited version and see if the error still happens
I tried with an unedited script. Same error.
Hello, Adiktuzmiko.

I wanted to use your script in my current project ("Dragonblood") in order to save the ending obtained by the player (just in case I make a sequel).

However, when I want to playtest the game (and test the script at the same time), RGSS3 says:

Script 'GameCustomData' line 219: SyntaxError occured.unexpected $end, expecting keyword_endStrange, because I read the script and found no missing equivalent to a 'begin' (sorry, I'm not into Ruby that much, I prefer C++).

Deleting the last 'end' gives another error, and adding one does too.

Thanks in advance for your answer.
I'm having the exact same problem like this.

Hasn't changed anything yet. 
I missed one end at one of the methods... updated!
Hate to be a bother, but I got another error for the "Persistent Variables & Switches" add-on. 

I haven't changed anything yet (even the switches and variables).

Code:
Script 'Persistent Data' line 56: SyntaxError occurred. unexpected '|', expecting '}' ...persistent_switch).each do {|key,value| $game_switches[key...
Go to that line and delete the "do", do the same for the line below that. Can't update right now, so...
So, after I delete the do, this is what it looks like:

CustomData.get🙂persistent_switches).each {|key,value| $game_switches[key] = value}CustomData.get🙂persistent_variables).each {|key,value| $game_variables[key] = value}And I get the error:

Script 'Persistent Data' line 56: NoMethodError occurred

undefined method 'each' for nil:NilClass

I really appreciate the help 🙂
Ah... because those aren't yet saved into the file, most probably...

Replace the whole DataManager part of the script with this

Code:
module DataManager  class <<self; alias create_game_objects_customdata create_game_objects; end  def self.create_game_objects    create_game_objects_customdata	CustomData.get(:persistent_switches).each {|key,value| $game_switches[key] = value} unless CustomData.get(:persistent_switches).nil?	CustomData.get(:persistent_variables).each {|key,value| $game_variables[key] = value} unless CustomData.get(:persistent_variables).nil?  end  end
It's not displaying the previous error 🙂

but when I turn the persistent switch ON, it's showing this error: 

Code:
Script 'Persistent Data' line 67: NoMethodError occurred. undefined method '[]='for nil:NilClass
what is line 67?
This

      x = $adik_custom_data[😛ersistent_switches][switch_id] = valueIt's a part of class games_switches

Code:
class Game_Switches  alias set_switch_adik []=  def []=(switch_id, value)    set_switch_adik(switch_id, value)    if ADIK::PERSISTENT_DATA::SWITCHES.include?(switch_id)      x = $adik_custom_data[:persistent_switches][switch_id] = value => line 67      DataManager.save_customdata if ADIK::DATA::AUTOSAVE    end  end end
Ah, the hash isn't yet made, forgot to initialize that.

Code:
#Add this code into the persisten data script, before the DataManager part$adik_custom_data[:persistent_switches] = {}$adik_custom_data[:persistent_variables] = {}
$adik_custom_data[😛ersistent_switches] = {} => LINE 50$adik_custom_data[😛ersistent_variables] = {}module DataManager  class <<self; alias create_game_objects_customdata create_game_objects; end  def self.create_game_objects    create_game_objects_customdataCustomData.get🙂persistent_switches).each {|key,value| $game_switches[key] = value} unless CustomData.get🙂persistent_switches).nil?CustomData.get🙂persistent_variables).each {|key,value| $game_variables[key] = value} unless CustomData.get🙂persistent_variables).nil?  endend

 

So, the code now has become like that,

but it results in another error >< (or maybe I copied it wrongly?)

Script 'Persistent Data' line 50: NoMethodError occurred.

undefined method '[]=' for nil:NilClass
Did you by any chance placed the persistent script above the Custom Data? Because else I couldn't think of any problems as that line was for initialization. You could also try moving them below this one instead

Code:
create_game_objects_customdata
Putting it below that line makes it not displaying the error anymore, indeed.

However, it seems that it isn't making the switch persistent. I made it ON in a previous playthrough and restart the game, and check that the switch is still OFF. 
Of course it won't, coz I realized it just now. Putting the initialization after the game object creation makes it such that the hash is always empty before the script checks for persistent switches and variables. Try to put it above the line instead of below.


You didn't answer the first question though, did you put the persistent script before custom data?
I put the persistent data below the custom data script. 

Putting the initialization below the line specified by you fix the error but doesn't actually make the switch persistent.

I have added the switch number in persistent data script and the autosave option is ON by default, so it's set to autosave. 

Original thread: https://forums.rpgmakerweb.com/threads/game-custom-data-v1-26.20304/