SQLsave

author:
http://www.lucaspaakh.com
description:
A simple way to save games using a SQL database in Air.
compatible:
any
depend:
none
tag:
SQL, save, database, simple, easy, sharedobjects
homepage:
https://gist.github.com/Kajenx/b5561a848ca93ddc5dec
download:
https://gist.github.com/Kajenx/b5561a848ca93ddc5dec/download

Overview

This is a simple class that works just like the SharedObjects in flash. Essentially, it just saves an object into an encrypted SQL database. It should work well for storing the information most games need to store, like the current level or a username.

Use this to initialize:

// NOTE: this isn't the most secure way to create an encryption key
var tempByte:ByteArray = new ByteArray();
tempByte.writeUTFBytes("BLAHblahBLAHblah"); // use a 16 character string
 
var MobileSave:SQLSave = new SQLSave("NAME_OF_FILE", tempByte);
 
// The "data" object is automatically populated when SQLSave starts,
// so you can immediately set your variables
MyVariable = MobileSave.data.MyVariable;
MyVariable2 = MobileSave.data.MyVariable2;

Then, use this to save data later:

MobileSave.data.MyVariable = MyVariable;
MobileSave.data.MyVariable2 = MyVariable2;
 
// Unlike SharedObjects, you MUST call the flush function to save
// to the database every time!  Don't call this too often.  Maybe when
// the player switches levels or hits a check point.
MobileSave.flush();

Changelog

  • 2014/09/12 16:41: First public version

Source Code

%gist(b5561a848ca93ddc5dec)%

User Comments

Feel free to edit this part of the page!

  extensions/sqlsave.txt · Last modified: 2015/03/11 15:05 by 127.0.0.1
 
Powered by DokuWiki