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!
How large is your file?
How large is your file?
Almost 150 byte
I hope that's what you need.

Write:
Read:
Good luck.
But how do i write to variable?
Or am i forgetting something?
I hope that's what you need.

Write:
Read:
Good luck.
Replace:
Code:
file = File.open...

By this command:
Code:
$game_variables[ID] = File.open...
I am getting a error that i don't know what it is.
I get this error for pretty much anything that i try.
Anything that i can try to solve this error?
Sorry...

Try this at the end:
$game_variables[ID] = file
ID = Number of Variable

Sorry, I'm away from my computer, I'll test it later and edit this message.
I am not understanding what am i doing wrong.
This time, i can put the files "content" in a variable, but instead, i get this in the variable
"#<File:0x8f218d8>"
Anything that i can do?
"#<File:0x8f218d8>"
Anything that i can do?
It seems that you simple put the memory location data into the variable.
file = file.open(...blah, blah
$game_variables(ID) = file <- all that will do is find the memory location data and place it into the variable.

Did you read Hime's information on the file reading?

Use the custom file read method if it is not a marshaled file.
then in the code line use something like
Ruby:
filedata = nil # nil = simple data, [] = array, {} = hash
data = load_data("Data/yourfile.ext")
data.split(/\r?\n/).each do |line|
  filedata << line
end
$game_variables[ID] = filedata
Sorry, I'm away from my computer, I'll test it later and edit this message.
brother, I ask for a little patience, I'm not at home, so I do the tests with the code.
When I finish I post an example of the complete code.

😉
Sorry..
brother, I ask for a little patience, I'm not at home, so I do the tests with the code.
When I finish I post an example of the complete code.

😉
I imagine that you will record some simple data, without breaking lines.

Write file:
Ruby:
obj=File.open('myfile.txt','w')
obj.write("Your string")
obj.close

Read first line:
Ruby:
File.open('myfile.txt', 'r') do |file|
   $game_variables[1]=file.readlines[0]
end

If you need to read the last line, you will need something more complex.

I'm hope your feedback
This error are starttiing to get annoying..
{
File.open('q.txt', 'r') do |file|
@lines.push line
end
$game_variables[1]=@lines[0]
}
This error are starttiing to get annoying..
Would be easier to read if you used code tags.
That error is easy to see what is wrong.
in the command you are saying do |file| then you say line.
Plus you also don't have it in the correct format.
@lines.push(file)
or @lines << file


If you need to read the last line, you will need something more complex.
Would that not just be $game_variables[1]=file.readlines[-1]
@LezianD Sorry, I was editing, please review there.

@Roninator2 Wow, that really is it. Thanx
I stiill don't get anything...
Am i even using the rigth scritp?
Can some body let a demo scritp so i can know what is wrong with it?
Download the attachment and follow this step by step:
  1. Create a new project with just a map (0001)
  2. Put the player's starting position on it
  3. Close Rpg Maker
  4. Extract the attached file
  5. Copy "Map0001" or "Map0001.rvdata2" to the "Data" folder of the new project
  6. Confirm to replace
  7. Open the new project and test the game
Good luck
Thank you! working fine!
Out of curiosity, what did you do that didn't work before?

The example I sent is exactly the same as this:
#13

Original thread: https://forums.rpgmakerweb.com/threads/how-can-i-read-write-a-file-to-a-variable-vxace.134798/