Main Menu
  • Welcome to The RPG Maker Resource Kit.

Reading Data

Started by Zethzune, December 30, 2009, 07:01:35 PM

0 Members and 1 Guest are viewing this topic.

Zethzune

Is it possible to load something other than save data from a file?
I am working on a menu screen to read books instead of using events and messages or something sloppy like that. I want to be able to load text for books in the game out of a data file rather than putting the text into the code. Currently I have to store the text in the code.


   @data = []
   case $game_temp.journal
   when 1 #Cyrilis Omikar
     @data.push("[This book is blank]")
     @data.push("")
   end


I have no problem with loading the text line by line but I'd prefer that the lines were coming from a file instead of out of the game code.

My strength is that of ten men, for I am wired to the eyeballs on espresso!

shaz

sure.

f = File.open(filename, "r")
while text = f.gets
  print text
end
f.close
Always remember you're unique.
Just like everybody else.

Zethzune

Quote from: shaz on December 30, 2009, 09:10:24 PM
sure.

f = File.open(filename, "r")
while text = f.gets
  print text
end
f.close

What is "r"?
My strength is that of ten men, for I am wired to the eyeballs on espresso!

shaz

"r" means for reading.  You're opening the file for reading.

or, instead of the print text that I have above, you'd just use @data.push text
Always remember you're unique.
Just like everybody else.

Zethzune

Quote from: shaz on December 30, 2009, 09:34:52 PM
"r" means for reading.  You're opening the file for reading.

or, instead of the print text that I have above, you'd just use @data.push text

Thanks, that works great. Now if only I could get modern algebra's paragraph formatter working in my game D:
My strength is that of ten men, for I am wired to the eyeballs on espresso!

shaz

hehe - you'll have to go to MA for help with that one ;)
Always remember you're unique.
Just like everybody else.

Zethzune

#6
Quote from: shaz on December 30, 2009, 09:48:36 PM
hehe - you'll have to go to MA for help with that one ;)

Edit (Apparently I forgot how to communicate): Would it be possible to modify that code to recognize a "page break" in the file so I can split text into multiple pages?

[spoiler]Any ideas on how to make scrolling windows without a selection bar? My class window_reader is a child of window_selectable to get the scrolling function but apparently that only works if there is selectable items in the window. I was thinking the other solution would be to have multiple pages but the load method there gives me the whole file... Is there a way I could put a marker in the file to split it into pages, or only get the file 16 lines at a time? I feel like a retard but I don't understand how the file operations work. x_x[/spoiler]
My strength is that of ten men, for I am wired to the eyeballs on espresso!

shaz

you could just increment a counter each time you read a line, and pause for player input after 16 lines.

Or you could put a special code - something like [page] as a line in the file, and each time you read a line, see if the text read in is [page] - if it is, stop reading.

This makes it a bit more complicated.
Always remember you're unique.
Just like everybody else.

Zethzune

#8
Next question. It doesn't seem to be able to read special characters like "ü". Would it be possible to fix this?

I seem to have fixed it. I wrote a substring substitution thing like in the base message code to replace \:u with ü. The base RMXP code is a mess, it's all class based for no reason; the code is just duplicated everywhere instead of being part of the parent class. I have an overwhelming urge to tear it all out and rewrite the RMXP base code myself. @_@ must not OCD.

I'm going to see if I can move substring substitution out of the window_message class and into the window_base class so it's accessible anywhere.
My strength is that of ten men, for I am wired to the eyeballs on espresso!

shaz

sorry - that's more than I know.  Is it not reading it, or not displaying it?  Is it possible that the font you've chosen doesn't have those special characters?
Always remember you're unique.
Just like everybody else.

ngoaho

for text file (*.txt)
read:
file = File.open("filedir","r")
contents = file.read
file.close

write at end of file:
my_string = "oh my god"# only string allowed
file = File.open("filedir","a")
file.write(my_string)
file.close

overwrite:
my_string = "oh my god"
file = File.open("filedir","wb")
file.write(my_string)
file.close


for rpg maker xp file(*.rxdata)
save
var = "cuckoo"# can be array, number,....
file = File.open("filedir","a")# replace "a" with "wb" for overwrite
Marshal.dump(var, file)
file.close

load
file = File.open("filedir","r")
var = Marshal.load(file)
file.close