Love_INI_Paser: how to read and write headers with variables?

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
Shadowblitz16
Citizen
Posts: 73
Joined: Wed Oct 28, 2015 11:18 pm

Love_INI_Paser: how to read and write headers with variables?

Post by Shadowblitz16 »

can someone tell me how to read and write ini headers based on a string variable?

this is the example he gives but it uses variable names and not variable values

for example I want to eventually make a game where there is an editor and the user can make tiles, npcs, items, and backgrounds and then add them to the editor

Code: Select all


ini = require('ini')
game = {}

-- Resource functions
function game:loadTiles()
	-- Load all tile config's here depending on how many there are in the folder
	
	-- Load all tile properties
end
function game:getTile(tile)
	-- Return tile id
end

return game
User avatar
BroccoliRaab
Prole
Posts: 8
Joined: Tue Jun 27, 2017 3:58 am

Re: Love_INI_Paser: how to read and write headers with variables?

Post by BroccoliRaab »

Given their example:

Code: Select all

local LIP = require 'LIP';

local data =
{
	sound =
	{
		left = 70,
		right = 80,
	},
	screen =
	{
		width = 960,
		height = 544,
		caption = 'Windows caption',
		focused = true,
	},
};

-- Data saving
LIP.save('savedata.ini', data);
You can instead do :

Code: Select all

local LIP = require 'LIP';

local data =
{
	["sound"] =
	{
		left = 70,
		right = 80,
	},
	["screen"] =
	{
		width = 960,
		height = 544,
		caption = 'Windows caption',
		focused = true,
	},
};

-- Data saving
LIP.save('savedata.ini', data);
I ran this and it worked however in the LIP source code I had to change line 44 from. (This is irrelevant to your question, however if LIP throws an error this will probably solve it):

Code: Select all

local file = assert(lovefile:open('w+b'), 'Error loading file :' .. fileName);
to

Code: Select all

local file = assert(lovefile:open('w'), 'Error loading file :' .. fileName);
Post Reply

Who is online

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