A Saving Lib? [SOLVED]

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.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: A Saving Lib?

Post by Nixola »

If the post is the answer at a question that requires a one-word answer, yes (I think)... Anyway, writing 'a_table{}' seems to call the __call field of the metatable of a_table (I didn't know it until a few minutes ago). If you want to write the content of the table you should either create a function that turns a table into a string (or something like that) or find a library that does it for you (like json4lua)
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: A Saving Lib?

Post by Robin »

Nixola wrote:Anyway, writing 'a_table{}' seems to call the __call field of the metatable of a_table (I didn't know it until a few minutes ago).
f{} is syntactic sugar for f({})
It works with string literals too. (That's how you can write require "something".)

If you try to call a table, it indeed looks at the __call field of the metatable.

Put those two together, and you get the apparent behaviour.
Help us help you: attach a .love.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: A Saving Lib? [SOLVED]

Post by Nixola »

Thanks Robin
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
Davidobot
Party member
Posts: 1226
Joined: Sat Mar 31, 2012 5:18 am
Location: Oxford, UK
Contact:

Re: A Saving Lib? [SOLVED]

Post by Davidobot »

I used json it worked perfectly.
PM me on here or elsewhere if you'd like to discuss porting your game to Nintendo Switch via mazette!
personal page and a raycaster
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: A Saving Lib? [SOLVED]

Post by T-Bone »

Or, you could just write valid lua syntax to a file with love.filesystem and then just require the file to load it. Like this:

Code: Select all

string = "a = ".. a.. "/n b = ".. b
love.filesystem.write("data.lua", string) 

--to load
require "data"
 
This example works for numbers, but can easily be changed to work with strings and other objects as well, including tables.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 2 guests