Help Support the Baja Engine! Donate to Breezeway Studios!
Save/Load

Search:

Saving/Loading game state



Code

fileSerializeBuffer=""

function fileSerializeDo(table)
        fileSerializeBuffer=fileSerializeBuffer.."{"
        
        for k,v in pairs(table) do
                fileSerializeBuffer=fileSerializeBuffer..k.."="
                
                if type(v)=="number" then
                        fileSerializeBuffer=fileSerializeBuffer..v
                elseif type(v)=="boolean" then
                        if v then
                                fileSerializeBuffer=fileSerializeBuffer.."true"
                        else
                                fileSerializeBuffer=fileSerializeBuffer.."false"
                        end
                elseif type(v)=="string" then
        fileSerializeBuffer=fileSerializeBuffer.."'"..v.."'"
                elseif type(v)=="table" then
        fileSerializeDo(v)
                end
                
                fileSerializeBuffer=fileSerializeBuffer..","
                
        end
        
        fileSerializeBuffer=string.sub(fileSerializeBuffer,1,#fileSerializeBuffer-2)
        
        fileSerializeBuffer=fileSerializeBuffer.."}"
end

function fileSerialize(table,file,tablename)
        fileSerializeBuffer=tablename.."="..returnSerialize(table)
        
        io.output(file)
        io.write(fileSerializeBuffer)
        io.close()
end