M MY Multiplayer: Wiki
Side
Kind

fileOpen

Shared

Opens a file that already exists, with the position at its start.

file|false fileOpen(string path [, bool readOnly = false])

Parameters

NameTypeDescription
pathstringThe path. A path inside the calling resource, or @resource/path for another resource's file. Another resource's file only opens with readOnly.
readOnlyboolIf true, the file opens for reading only.default false

Returns

The open file, or false if it does not exist, is a folder or could not be opened.

A path may not contain .., \ or :, nor start with /. Another resource's files can only be read; an invalid path logs a warning and the function returns false. The file is closed when the resource stops.

Example

local file = fileOpen("@maps/spawns.json", true)
if file then
    local spawns = fromJSON(fileRead(file, fileGetSize(file)))
    fileClose(file)
end

See also