Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Making a file?

I found a strange error with File.open (which can be used to make files that don't exist)
where i used the filename 'File.gtdata', and got:

No such file or directory "File.gtdata"

Is there a method to make files without opening them?
 
actually, you didn't include the full set of methods. In this case, you want to tell it your are opening a file to write data to it. So, you would use the following code:

Code:
file = File.open("File.gtdata", "wb")

Now, the "wb" stands for "write binary". There are other strings you can use, like "r" or "rb", which both amount to "read binary", as well as seperate versions for text files. If I remember correctly, they are the same as if you were writing in C/C++, so if you must, go ahead and look it up.

Also, a quote from the help file on the open command:

RMXP Help File":1dp6u5sc said:
open(file[, mode]) {|io| ... }

Opens file and returns a File object. mode specifies one of the following strings. When mode is omitted, the default is "r".

  • "r": Opens file in read mode.
  • "w": Opens file in write mode. If a file already exists when file is opened, the previous file's contents will be deleted.
  • "a": Opens file in write mode. Output will always be appended to the end of the file.

Using "+" opens the file in read-write mode (RDWR):

  • "r+": Sets the read-write position to the beginning of the file.
  • "w+": The same as "r+", but if a file already exists when file is opened, the previous file's contents will be deleted.
  • "a+": The same as "r+", but if a file already exists when file is opened, the read-write position will be set to the end of the file.

The "b" flag can also be added to any of these (in the format "r+b") to open the file in binary mode.

When open is called along with a block, it opens the file, executes the block, then closes the file when execution is complete. In this case, returns the result of the block evaluation. That is:

Code:
open(path, mode) do |f|

   ...

end

 

# almost identical to the above

f = open(path, mode)

begin

   ...

ensure

  f.close

end

You know, it's amazing how helpful the RMXP help file is when compared to most programs. I mean, it not only tells you how to use the basic program, but how to do a lot of stuff in Ruby and RGSS.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top