file_text_open_write

这个函数打开文本文件,指定文件名为 只写 ( 如果文件不存在,则创建它),返回文件的唯一 id,该文件应该存储在一个变量中,因为它将用于对该文件进行的所有进一步操作。

In the case of an error, the function will return -1. However, in some cases where the file could not be loaded (like an invalid filename being passed), the function may still return a file ID, in which case the return value of the file closing function will be false.

如果文件已经存在,则使用此函数将导致在保存数据时覆盖该文件。如果您想在保持文件现有内容不变的情况下向文件添加数据,请使用 file_text_open_append()

NOTE You can only have a maximum of 32 files open at any one time. You should also always close files when finished as this writes the information and frees the memory associated with the file.

WARNING This may not work as you expect due to GameMaker being sandboxed! Please see the section on The File System for more information.

 

语法:

file_text_open_write(fname);

参数类型描述
fnameString要写入的文件的名称。

 

返回:

Text File ID or -1

 

例子:

var file;
file = file_text_open_write(working_directory + "level.txt");
file_text_write_string(file, level_data);
file_text_close(file);

上面的代码将打开文件“level.txt”进行写入,然后写入存储在变量“level_ data”中的字符串,最后再次关闭该文件。