Is there any way to write or create files to a specified file path that isnt inside the game folder? I want to include a feature in my game that checks if you've beaten it and adds content to another game, but i don't know how to make RPG Maker XP games create the file that the other game is checking for, if that makes sense. Please let me know if and how i can make this work! (I don't know if this is exactly a script request but i'm imagining its going to have to deal with scripting so i stuck it here anyways)
Write files to specified path outside of the game folder
RGSS Script RequestsBefore anything, what I'm going to show is just to start understanding how writing and reading files works, I don't have deep experience with Ruby or RGSS10? (Native)
Works with RMXP too:
forums.rpgmakerweb.com
File exist (Check):
Sample (Lines to Array):
Distribute the lines into variables:
Creating non-editable files will require more knowledge, verification methods, for example, using an initial game variable that receives a random value and using it as a unique player TOKEN, so if you copy it from one player to another it would not work at the time of reading.
Sample (Write file):
Due to the limitations of the RMXP text box for sending script commands and automatic encapsulation, I saved the variables and the switch in temporary variables.
Keep in mind that using File.open will overwrite the file, so the best option is to use very small data, for example.
Regarding the Switch, I had to define it as a numeric value to make it easier to return the data.
Sources:
Works with RMXP too:
How can i Read/write a file to a variable? (VXAce)
Do somebody know how can i put the content of a file to a varable? And if i can, how can i write that variable to a text box? Do i use a \v[id], or i need to use something else? Any code that may help is of a great help!
forums.rpgmakerweb.com
File exist (Check):
Sample (Lines to Array):
Ruby:
f = File.read("myfile.txt")
f = f.split("\n")
p f[0] # line 1
p f[1] # line 2
p f[2] # line 3
Distribute the lines into variables:
Creating non-editable files will require more knowledge, verification methods, for example, using an initial game variable that receives a random value and using it as a unique player TOKEN, so if you copy it from one player to another it would not work at the time of reading.
Sample (Write file):
Ruby:
t=$game_variables[5000] # token
$game_switches[1] ? s=1 : s=0
v=$game_variables[1]
f=File.open('myfile.txt','w')
f.puts t
f.puts s
f.puts v
f.close
Due to the limitations of the RMXP text box for sending script commands and automatic encapsulation, I saved the variables and the switch in temporary variables.
Keep in mind that using File.open will overwrite the file, so the best option is to use very small data, for example.
Regarding the Switch, I had to define it as a numeric value to make it easier to return the data.
Sources:
A switch as a numeric value? Thst's too C or C++-centric indeed. 😅
Well, it depends on what you need to save in this new directory. Do you want the file to act like some initialization file a la Game.ini? Or do you need to store very specific data like specific variables and switches?
If it's the latter, then you'd just save them via File.open and then several calls to Marshal.dump before ending with file.close
Well, it depends on what you need to save in this new directory. Do you want the file to act like some initialization file a la Game.ini? Or do you need to store very specific data like specific variables and switches?
If it's the latter, then you'd just save them via File.open and then several calls to Marshal.dump before ending with file.close
I see, so every time I use the dump or load function it means it will move on to the next item without having to work with an Array.
Ruby:
f = File.open("myfile.txt","wb")
Marshal.dump($game_switches[1],f)
Marshal.dump($game_variables[1],f)
f.close
Ruby:
f = File.open("myfile.txt","rb")
$game_switches[1]=Marshal.load(f)
$game_variables[1]=Marshal.load(f)
f.close
Original thread: https://forums.rpgmakerweb.com/threads/write-files-to-specified-path-outside-of-the-game-folder.179640/