Skip to content
Vadim edited this page Sep 1, 2014 · 4 revisions
    --While you exit from app, data save. And while you will open this, data load
    Slib = require "slib"
    
    function love.load()
        Slib.init("Slib")
    
        if Slib.isFirst() then --if there is no save
            g = {} --char stats
            g.hp = 50
            g.dmg = 100
            g.def = 10
        else --if there is save file
            g = Slib.load() 
        end
    end
    
    function love.update(dt)
        if love.keyboard.isDown('g') then
            g.hp = math.random(10, 5000) --generate new stats
            g.dmg = math.random(10, 5000)
            g.def = math.random(10, 5000)
            Slib.saveE(g) --save stats with encription
        end
    end
    
    function love.draw()
        --draw our stats:
        love.graphics.print("HP: " .. g.hp .. " Dmg: " .. g.dmg .. " Def: " .. g.def, 10, 10)
      
        love.graphics.print("Press G to generate random HP, Dmg, Def, and save them!", 10, 30)
    end

And it is example's save file: Vf-Zq3SI?k$Zm6PNfb"$w0RUXla-xlDk&`Rk&PbT)]&2l`~_n}BB So, are it doesn't amazing?

But be careful! Slib can't save custom userdata. And if your table have some this:

        g = {} --char stats
        g.hp = 50
        g.dmg = 100
        g.def = 10
        g.img = love.graphics.newImage("Player.png")
        g.body = love.physics.newBody(world, 10, 10, "Shape")

For save this table, you must write "image" and "body" in "drop" parameter. Like this:

    --Parametes: table to save, save file, drop parameter
      slib.saveE(g, "save.file", {"image", "body"})

And g.img, g.body don't save. When you load table, you must call function again!

In result, it's very easy!

Clone this wiki locally