beetlebug▾
/

ztk::game save

Writes a dict as the save of a name.

ztk::game save NAME DICT

Description

NAME has 1 to 64 characters of a-z, 0-9, _, and -, so a name cannot leave the folder of the saves. The write goes to a temporary file and then a rename, so a crash leaves the old save. A save has at most 1,048,576 bytes, and the folder at most 64 saves.

The saves go to the folder game-saves of the folder of tk appdata, the data folder of the app. That needs no capability. When tk appdata gives no folder, as on a desktop, a save goes to a file only with the capability file, which the ztk program has by default: to game-saves of the current folder of the file commands, or of the root folder of --root. With no folder of tk appdata and no capability file, ztk::game save writes no file, and the saves stay in memory for the run, as on the web. The key store of ztk::game info gives files or memory.

Returns

An empty string.

Examples

% ztk::game save best {score 12 level 3}
> dict get [ztk::game load best] score
12

Errors

% ztk::game save ../best {score 1}
bad save name "../best": must be 1 to 64 characters of a-z, 0-9, _, and -
-errorcode ZTK GAME SAVE NAME

% ztk::game save a/b {score 1}
bad save name "a/b": must be 1 to 64 characters of a-z, 0-9, _, and -
-errorcode ZTK GAME SAVE NAME

% ztk::game save {} {score 1}
bad save name "": must be 1 to 64 characters of a-z, 0-9, _, and -
-errorcode ZTK GAME SAVE NAME

% ztk::game save [string repeat a 65] {}
bad save name "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa": must be 1 to 64 characters of a-z, 0-9, _, and -
-errorcode ZTK GAME SAVE NAME

% ztk::game save best {score}
missing value to go with key
-errorcode TCL VALUE DICTIONARY

% ztk::game save big [list data [string repeat x 1048576]]
the save "big" has more than 1048576 bytes
-errorcode ZTK GAME SAVE SIZE

Facts

Capability
None.
Tcl release
Tcl 9.1 and 8.6.
Since
ztk 1.0.0-beta.7

See also