Variable that transcends individual saves?

● ARCHIVED · READ-ONLY
Started by Dymdez 20 posts View original ↗
  1. Hey! The intro to my game is a bit long and I was hoping to give someone the option to skip the intro provided they have already watched. Is it possible to setup a variable or switch that transcends individual saves to give the player an option to skip the intro? Thanks.
  2. just have the variable save / be read from a specific file - example:

    module GlobalSaveData # GlobalSaveData::read_file def self.read_file Marshal::load(File::open('System/filename.rvdata2','rb')::read) end # GlobalSaveData::save_file(data) def self.save_file(data) File::open('System/filename.rvdata2',wb) do |file| Marshal::dump(data,file) end endendAnd then you can do script calls like this:

    data = GlobalSaveData::read_fileand

    GlobalSaveData::save_file(data)For example:

    If you wanted to save a true / false value as the data, do this:

    GlobalSaveData::save_file(true)and then when you call read_data it will return that object (true).. Could also do arrays/hashes of datasets or whatever, but yea..
  3. Thanks Dek,

    So just correct me if I'm wrong...

    I just run the script call "GlobalSaveData::save_file(true)" after the intro ends and then I setup a conditional branch before the intro begins, checking to see if that variable is true, and if so, to skip to after the intro?

    P.S. Is Marshal just IO for rvdata? Do I use your little scriptlet above?
  4. Quote from RGSS3 help: "Marshal: A module providing the functionality for writing a Ruby object to and reading it from a file (or string)."

    Actually, you could probably use the default load_data and save_data methods in place of that, cause they do similar things.. :D

    But yea, your probably best to read the file before the conditional - during some load sequence or something - sometime it wont be noticeable, just in case there is a slow read on the data for some reason.. Just do something like this:

    $game_variables[1] = GlobalSaveData::read_dataa little before you need the conditional, and then check variable 1 (or whatever).. Course you could just put the script call into the conditional directly - it would work just the same (might have the slow load issues very rarely on slower machines though)
  5. Thanks, the file that we check at the beginning doesn't initially exist, what's the best way to make it?

    Any idea?

    UjippOe.jpg
  6. Apologies - I never actually tested anything, just started replying to you with my brain powahhhh :D

    module GlobalSaveData # Filename constant - set to whatever: FILENAME = "mykewelfile.dek" # GlobalSaveData::read_file def self.read_file save_file(nil) unless FileTest::exist?(FILENAME) Marshal::load(File::open(FILENAME,'rb')::read) end # GlobalSaveData::save_file(data) def self.save_file(data) File::open(FILENAME,'wb'){|file| Marshal::dump(data,file)} end # GlobalSaveData::test_print def self.test_print puts "TEST PRINT: %s" % read_file end # End ModuleendI added a method for testing - feel free to remove it, or use it for testing :D
  7. Thanks, nice work Dek! Works perfectly

    but I have one concern... When I rename the file to see if it still prompts to skip, for some reason, it still does, which leads me to believe if I compress the file for others to play the game, they'll be given the option to skip without first having seen the intro, even when I delete the file. Why does it prompt to skip even when I delete the text file assigned ? So just to be clear, the file that we save the variable in to check if the intro has already been seen, when I delete that file, it still prompts to skip, which it shouldn't since the file telling it to skip doesn't exist anymore. Why is the global variable persistent?
  8. I'm not sure what you mean..

    Once the intro has been seen, and you call the script call to save the data passing in 'true' as the data argument, the read_data method should always return true. - once the file is deleted, when the read_data method is called, it will return 'nil', which is just the same as 'false' when checking in a conditional.

    So like..

    $game_variables[1] = GlobalSaveData::read_filewill either hold nil (false) or true.

    Providing the option is only being shown when the variable above is true, it should never be shown when the file has been deleted (or the intro has not yet been viewed).

    When that game file is then saved, the $game_variables data is saved along with it - so if its true then, it will always be true (for that particular save file).

    If you were to delete the file, and start a new game, the option should not be shown.
  9. I agree, but imagine my confusion when the prompt came up even though I deleted the file. Any ideas? Is it somehow saved elsewhere?

    Edit: false alarm, it was being saved in the project folder, for some reason I thought it was saved in the system folder! Thanks dek, that was great help I appreciate it.
  10. oh yea, thats my fault - I changed the filename and folder :D

    No worries ^_^
  11. I've moved this thread to RGSS3 Script Requests. Please be sure to post your threads in the correct forum next time. Thank you.
  12. If you're going to do lots of that, you could try to use my Custom Game Data script. :)
  13. Thanks guys, and I definitely will utilize those scripts if I do more of this in the future -- I had no idea it was so accessible, I've really come around on my opinion of RPGMaker limitations - thanks again.
  14. The only limitations of RPG Maker are within the person who wields it! (so updating my status with that) ^_^
  15. First, this conversation has been quite useful in regards to myself so I'm glad it's happened.

     

    Conceptually (code-wise too), isn't it far simpler and perhaps more effective to check if a save file exists and if so allow the user to skip the scene?  The existence of the save likely proves that they went through the intro (assuming they can't save during).  The only draw back I see to this is if you are worried about multiple people playing on one system but even then they could elect to view it.

     

    Just a thought. 
  16. It's a good thought, but it overlooks the possibility of someone watching the intro but forgetting to save! Of course, this fear is not substantial, but none the less, why not be certain to cover all bases?

    Just curious, how do you check for a saved file existing?
  17. Use this in a conditional branch:

    DataManager.save_file_exists?

    This is also the same method used on the title screen load to check if the save file is available or not,

    and to decide where to put the cursor and whether or not to grey out the load command.

    Edit:

    What Jelly said about code wise is true. And i am sure you can find some good examples using this method in existing games. (A lot of the famous games out there still require you to go through the intro again if you forgot to save and restart the game)

    Reason is, if you rely on an external save file, and the code you use didn't provide a check mode, you will be rewriting and loading the file every time you plays the intro. So it's not HDD friendly. Especially if you play the intro before the title screen.
  18. Thanks, interesting and very useful.