xScal Scaleform API 0.4.34

Mod storage

One JSON document per name in Data/modsdata/<name>.json, through __SFCodeObj.modStorage.

Names are 1 to 64 characters of lowercase letters, digits, ., _ or -. They start with a letter or digit, do not end with ., and the part before the first . is not a Windows device name (con, nul, com1 and so on). Documents are non-empty, valid UTF-8 JSON, at most 5 MiB.

save validates the document and queues the write on xScal's file worker; it returns true once the write is queued. The file is replaced atomically when the worker runs. While a saved document is queued or being written, load returns it from memory; otherwise load reads the file, so edits made outside the game are picked up.

Names give organization, not access control. Any SWF can read or write any name. Storage does not write to xscal.log.

modStorage.save

Save a named JSON document

__SFCodeObj.modStorage.save(name:String, document:String):Boolean

Legacy form

__SFCodeObj.modStorage.save(document:String):Boolean

Saves under the name the movie registered with register. Returns false until then.

Arguments

NameTypeDescription
nameStringStorage name. Must not end with . or be a Windows device name.
documentStringComplete JSON document as a string, valid UTF-8, at most 5 MiB.

Returns Boolean

Validates the name and the document and queues the write. Returns false for an invalid name, invalid JSON, a document over 5 MiB, or when the file worker is not running or its queue is full.

Example

data.settings.bars.health.scale = 1.25;
var saved:Boolean = __SFCodeObj.modStorage.save(
    "improvedbars", JSON.stringify(data));

modStorage.load

Load a named JSON document

__SFCodeObj.modStorage.load(name:String):*

Legacy form

__SFCodeObj.modStorage.load():*

Loads the name the movie registered with register. Returns false until then.

Arguments

NameTypeDescription
nameStringStorage name. Must not end with . or be a Windows device name.

Returns *

String (the JSON document) or Boolean false.

Returns the stored document as a String, or Boolean false when the name is invalid or the file is missing, unreadable, invalid or over 5 MiB. Test with !== false.

Example

var stored:* = __SFCodeObj.modStorage.load("improvedbars");
if (stored !== false) {
    data = JSON.parse(String(stored));
}

modStorage.register

Bind the movie to one storage name (legacy)

__SFCodeObj.modStorage.register(name:String):Boolean

Arguments

NameTypeDescription
nameStringStorage name. Must not end with . or be a Windows device name.

Returns Boolean

Associates the calling movie with one storage name for the one-argument save and zero-argument load forms. Registration lasts for the movie session. Registering the same name again returns true; a different name returns false. The named forms do not need registration; use them when several child SWFs share one HUD movie.