RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
Reading Data

0 Members and 3 Guests are viewing this topic.

**
Rep: +0/-0Level 90
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.

Code: [Select]
   @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.

« Last Edit: December 30, 2009, 07:14:33 PM by Zethzune »
My strength is that of ten men, for I am wired to the eyeballs on espresso!

*
Rep:
Level 87
sure.

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

**
Rep: +0/-0Level 90
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!

*
Rep:
Level 87
"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.

**
Rep: +0/-0Level 90
"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!

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

**
Rep: +0/-0Level 90
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 for:
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
« Last Edit: December 30, 2009, 10:20:37 PM by Zethzune »
My strength is that of ten men, for I am wired to the eyeballs on espresso!

*
Rep:
Level 87
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.

**
Rep: +0/-0Level 90
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.
« Last Edit: December 31, 2009, 03:06:36 PM by Zethzune »
My strength is that of ten men, for I am wired to the eyeballs on espresso!

*
Rep:
Level 87
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.

**
Rep:
Level 82
for text file (*.txt)
read:
Code: [Select]
file = File.open("filedir","r")
contents = file.read
file.close
write at end of file:
Code: [Select]
my_string = "oh my god"# only string allowed
file = File.open("filedir","a")
file.write(my_string)
file.close
overwrite:
Code: [Select]
my_string = "oh my god"
file = File.open("filedir","wb")
file.write(my_string)
file.close

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