• Just a reminder that providing specifics on, sharing links to, or naming websites where ROMs can be accessed is against the rules. If your post has any of this information it will be removed.
  • Ever thought it'd be cool to have your art, writing, or challenge runs featured on PokéCommunity? Click here for info - we'd love to spotlight your work!
  • Which Pokémon Masters protagonist do you like most? Let us know by casting a vote in our Masters favorite protagonist poll here!
  • Red, Hilda, Paxton, or Kellyn - which Pokémon protagonist is your favorite? Let us know by voting in our poll!
  • 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.

[Scripting Question] Write Variables To Text File

  • 6
    Posts
    4
    Years
    • Seen Aug 17, 2021
    Hello.

    I was wondering if there is any way of exporting/writing variables to a .txt file upon saving the game or changing a variable. As far as i know there is no other way to read a .rxdata file outside of RPG Maker, so reading from the rxdata directly probably wouldn't work.

    Any possible help is greatly appreciated.
     
    Hello.

    I was wondering if there is any way of exporting/writing variables to a .txt file upon saving the game or changing a variable. As far as i know there is no other way to read a .rxdata file outside of RPG Maker, so reading from the rxdata directly probably wouldn't work.

    Any possible help is greatly appreciated.

    What variables are you talking about? You mean $game_variables / the variables you set in the Events with the option "Control Variables" in the Event commands?

    Paste this script somewhere:
    Spoiler:


    Call the function pbSaveVariablesToTxt in an Event or something if you want to print the variables.

    If you want to alter the variables, I suggest you do it with RPG Maker, rather than a script.
     
    I have a little problem. I've put the script at the end of PSystem_Utilities, but when I call the script in an event it doesn't write any variables or switches.
    https://pasteboard.co/JQK5jrZ.png
    https://pasteboard.co/JQK5uXB.png

    Replace my code with this:
    Spoiler:


    But if you run this at the start of a game, it's most probable that no variable is defined.
     
    Thank you for the quick reply. I tested your code and it showed a length of 0. And indeed, the problem was that no variables were defined yet. It worked as soon as I changed a variable before calling the function.
     
    Sorry for troubling you again, but I have one last question. Is there a way to read something in from a text file? For example: I have a text file with a 1 as the only text in it. I would like to read in this text file so it returns true if it reads in 1.
     
    Try something with:

    Code:
    def pbCheckIfEqual1
      File.open(filename,"rb") { |f|
        f.each_line { |line|
          return true if line == "1"
        }
      }
      return false
    end

    But I would strongly recommend NOT to use one file just for storing only one variable. The game variables are made for this purpose.
     
    Thank you, but the reason I asked this was because I'm working on a project where I could change something in the game by reading in sensors. In this case it's an ultrasonic sensor. If the sensor detects something in front, it will write a 1 to a text file, which i can then use in this function. Then I can use the conditional branch to change a variable if I need to.
     
    Back
    Top