Why not expand upon this thread and share my take on the map autosaving script in here as well for comparison:
Code: Select all
mapper = mapper or {}
if not mapper.modifiedSinceBackup then
echoM("Map was not modified. Skipping backup.")
-- elseif not mapper.connectedToGame then
-- echoM("Not connected. No backup necessary.")
-- BUT may have been changed anyway, then logged out without backup, so backup should happen anyway!
else
mapper.backupVersion = mapper.backupVersion or 0
mapper.backupVersion = (mapper.backupVersion + 1) % 5
local fileName = getMudletHomeDir() .. "/map/backup" .. mapper.backupVersion .. ".dat"
saveMap(fileName)
echoM("Map backed up as: \n" .. fileName)
mapper.modifiedSinceBackup = false
end
-- sysExitEvent
-- Raised when Mudlet is shutting down the profile
-- a good event to hook onto for saving all of your data.
Just copy/paste this in a timer and set the duration as you see fit, maybe one hour or so.
Features include:
- Do not save if map was not changed since last backup at all
- Backup to more than one file, just in case something went wrong earlier (default is to keep 5 versions)
To check for updates, add a new line in all your functions that edit map data (create new rooms or areas, etc.) like this:
Also you need two simple scripts hooking into the sysDisconnectionEvent etc. and toggle the bool checked above
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE MudletPackage>
<MudletPackage version="1.001">
<ScriptPackage>
<ScriptGroup isActive="yes" isFolder="yes">
<name>mapper.connectedToGame</name>
<packageName></packageName>
<script></script>
<eventHandlerList />
<Script isActive="yes" isFolder="no">
<name>connected</name>
<packageName></packageName>
<script>function connected()
mapper.connectedToGame = true
end</script>
<eventHandlerList>
<string>sysConnectionEvent</string>
</eventHandlerList>
</Script>
<Script isActive="yes" isFolder="no">
<name>disconnected</name>
<packageName></packageName>
<script>function disconnected()
mapper.connectedToGame = false
end
</script>
<eventHandlerList>
<string>sysDisconnectionEvent</string>
</eventHandlerList>
</Script>
</ScriptGroup>
</ScriptPackage>
</MudletPackage>
These are the actual two scripts in a folder, you can just copy/paste the whole shebang into the scripts editor tree and be done.
Let me know how it works for you, or if somebody has another different approach to saving maps, feel free to share your style, too!
edit: Included mapper table definition and updating modifiedSinceBackup