Help Using knife.serialize

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
CanadianGamer
Party member
Posts: 132
Joined: Tue Jun 30, 2015 1:23 pm
Location: Canada
Contact:

Help Using knife.serialize

Post by CanadianGamer »

I am trying to use a library called knife.serialize but I've never used a library before can anyone tell me how to make it work
My serious itch.io page:
https://pentamonium-studios.itch.io/
My less serious itch.io page:
http://canadiangamer.itch.io
User avatar
airstruck
Party member
Posts: 650
Joined: Thu Jun 04, 2015 7:11 pm
Location: Not being time thief.

Re: Help Using knife.serialize

Post by airstruck »

Dowload serialize.lua and put it in somewhere your project.

If you put it in a folder called "knife" you would include it like this:

Code: Select all

local Serialize = require 'knife.serialize'
Let's say you want to serialize a table named "data"

Code: Select all

local serializedData = Serialize(data)
Now the variable "serializedData" contains a string that can be saved to a file...

Code: Select all

love.filesystem.write('savegame.lua', serializedData)
...and later the file can be deserialized with dofile.

Code: Select all

local deserializedData = dofile('savegame.lua')
Now "deserializedData" contains a table equivalent to the original "data" table.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Help Using knife.serialize

Post by Nixola »

Never use "dofile" in LÖVE. Love.filesystem.load works better.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
airstruck
Party member
Posts: 650
Joined: Thu Jun 04, 2015 7:11 pm
Location: Not being time thief.

Re: Help Using knife.serialize

Post by airstruck »

Nixola wrote:Never use "dofile" in LÖVE. Love.filesystem.load works better.
Thanks, still not used to the way Love wants to interact with the filesystem. Dofile will break if you don't know the full path to the file, so the last code block should be something like this under Love:

Code: Select all

local deserializedData = love.filesystem.load('savegame.lua')()
User avatar
CanadianGamer
Party member
Posts: 132
Joined: Tue Jun 30, 2015 1:23 pm
Location: Canada
Contact:

Re: Help Using knife.serialize

Post by CanadianGamer »

Thank You for your help
My serious itch.io page:
https://pentamonium-studios.itch.io/
My less serious itch.io page:
http://canadiangamer.itch.io
User avatar
CanadianGamer
Party member
Posts: 132
Joined: Tue Jun 30, 2015 1:23 pm
Location: Canada
Contact:

Re: Help Using knife.serialize

Post by CanadianGamer »

Okay it is still not working I have it saving table settingsTable:

Code: Select all

settingsTable = {SoundFxSetting = true, MusicSetting = true}
in settings.lua by doing this:

Code: Select all

serializedSettingsData = Serialize(settingsTable)
love.filesystem.write('settings.lua', serializedSettingsData)
but settings.lua is still blank
My serious itch.io page:
https://pentamonium-studios.itch.io/
My less serious itch.io page:
http://canadiangamer.itch.io
User avatar
airstruck
Party member
Posts: 650
Joined: Thu Jun 04, 2015 7:11 pm
Location: Not being time thief.

Re: Help Using knife.serialize

Post by airstruck »

The code looks fine, it should work.

Love might not be saving the file where you expect, take a look at love.filesystem and love.filesystem.setIdentity to get an idea of how this works. You should be able to print(love.filesystem.getSaveDirectory()) to see where it's actually being saved.

If that doesn't solve it, upload a .love and I'll have a look (or someone else will).
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 90 guests