Skip to content

Latest commit

 

History

History
41 lines (27 loc) · 1.63 KB

getVersion.markdown

File metadata and controls

41 lines (27 loc) · 1.63 KB

save.getVersion()

 
Type function
Library save.*
Return value Number
Keywords load, save, version
See also Sample code, save.load(), save.save(), save.NO_FILE_VERSION

Overview

This function is used to get the version of the current save file. This can be called safely to check whether an older version is being used before save.load() is called, allowing different versions to use different keys. If you ever need to add or change keys for save files, you should change the version value passed to save.init() in your application, and call this function before loading the save file to determine which key to use (see example below).

If this function is called and no save file exists, then save.NO_FILE_VERSION will be returned.

Syntax

save.getVersion()

Examples

local save = require 'plugin.save'

save.init( "example.json", 2, {63, 54, 29, 63, 91, 82, 5}, "vbeiubv984nw0" )

-- Handle old versions
if (save.getVersion() == 1) then
	-- Use old key
	save.init( "example.json", 2, {36, 45, 92, 36, 19, 28, 5}, "bveiubv984nw0" )
	save.load()

	-- Start using new key
	save.init( "example.json", 2, {63, 54, 29, 63, 91, 82, 5}, "vbeiubv984nw0" )
	save.save()
end