Skip to content

Latest commit

 

History

History
39 lines (26 loc) · 1.2 KB

file_read_all_text.md

File metadata and controls

39 lines (26 loc) · 1.2 KB

Home > Community Toolbox Reference > File utilities

file_read_all_text

Go to source

Reads entire content of a given file as a string, or returns undefined if the file couldn't be read.

Arguments
Argument Type Usage Description
filename String Required The path of the file to read the content of.
Returns

Undefined,String

Example

The following code shows a function to load the number of levels completed from a simple save file.

function progress_load() {
    // load string from the save file
    // if the file cannot be loaded, use default "0" string
    var _save_text = file_read_all_text("save.dat") ?? "0";
    
    var _digits = string_digits(_save_text);
    if (_digits == "")
        _digits = "0"; // if the file contained a non-digit string, read 0 as well
    
    global.levels_completed = real(_digits);
}

Update history

  • 23.4.1 - Tweaked the JSDocs.
  • 23.4.0 - Created a function to read file contents as a string.