Static p5_sys::global::loadStrings[][src]

pub static loadStrings: LoadStringsInternalType
Expand description

Reads the contents of a file and creates a String array of its individual lines. If the name of the file is used as the parameter, as in the above example, the file must be located in the sketch directory/folder.

Alternatively, the file maybe be loaded from anywhere on the local computer using an absolute path (something that starts with / on Unix and Linux, or a drive letter on Windows), or the filename parameter can be a URL for a file found on a network.

This method is asynchronous, meaning it may not finish before the next line in your sketch is executed.

This method is suitable for fetching files up to size of 64MB.

Examples

let result;
function preload() {
  result = loadStrings('assets/test.txt');
}

function setup() {
  background(200);
  text(random(result), 10, 10, 80, 80);
}
function setup() {
  loadStrings('assets/test.txt', pickString);
}

function pickString(result) {
  background(200);
  text(random(result), 10, 10, 80, 80);
}

Parameters

filename name of the file or url to load

callback? function to be executed after loadStrings() completes, Array is passed in as first argument

errorCallback? function to be executed if there is an error, response is passed in as first argument