gema
Would you like to react to this message? Create an account in a few clicks or log in to continue.


A website for every gema-assaultcube fan
 
HomeHome  Latest imagesLatest images  SearchSearch  RegisterRegister  Log in  

 

 Loading a .cfg database

Go down 
2 posters
AuthorMessage
Baruch

Baruch


Messages : 105
Joined/Date d'inscription : 2012-08-04
Age : 32
Location/Localisation : France

Gema stats
farthest jump:

Loading a .cfg database Empty
PostSubject: Loading a .cfg database   Loading a .cfg database EmptyFri Aug 31, 2012 8:44 am

Hi everyone,

I made a script that uses a .cfg file, with the cfg.setvalue et cfg.getvalue functions. In that script, I'd like to load this file into an array like this :

My .cfg file :

[Lua Config File]
pikachu=46
Baruch=-15

My array :

{pikachu = 46 ; Baruch = -15}

The problem is that getvalue doesn't make it possible, because I don't know the indexes in the .cfg file.
Is there any solution to go through every line of the .cfg file ? (something like next())

I've seen that Sveark bypassed this problem by merging all the lines into one big line, and using separators. I'd like to avoid this solution, because I still want to be able to modify one line of my table without the need of loading everything.

Thank you
Back to top Go down
Baruch

Baruch


Messages : 105
Joined/Date d'inscription : 2012-08-04
Age : 32
Location/Localisation : France

Gema stats
farthest jump:

Loading a .cfg database Empty
PostSubject: Re: Loading a .cfg database   Loading a .cfg database EmptyFri Aug 31, 2012 8:56 am

Ah I think I found a solution :

I let my .cfg the same, and I make another .cfg file with all the indexes. This file will only have one line, with separators. What do you think ?
Back to top Go down
Baruch

Baruch


Messages : 105
Joined/Date d'inscription : 2012-08-04
Age : 32
Location/Localisation : France

Gema stats
farthest jump:

Loading a .cfg database Empty
PostSubject: Re: Loading a .cfg database   Loading a .cfg database EmptyFri Aug 31, 2012 9:31 am

It seems io library works, so I tried to use it but I can't get to anything xD.

file = io.open("test.cfg")

Do you know what argument I should use ? (this one doesn't work)

Sorry for triple post :/
Back to top Go down
Baruch

Baruch


Messages : 105
Joined/Date d'inscription : 2012-08-04
Age : 32
Location/Localisation : France

Gema stats
farthest jump:

Loading a .cfg database Empty
PostSubject: Re: Loading a .cfg database   Loading a .cfg database EmptyFri Aug 31, 2012 9:42 am

Ok this is really embarassing... Just do that :

for line in io.lines("./lua/config/test.cfg") do clientprint(cn, line) end

I hope this will help someone ^^
Back to top Go down
Sveark

Sveark


Messages : 124
Joined/Date d'inscription : 2011-05-02
Age : 30
Location/Localisation : Russia

Loading a .cfg database Empty
PostSubject: Re: Loading a .cfg database   Loading a .cfg database EmptySun Sep 02, 2012 4:01 am

You do that like Park does. For now, this is the only simple solution of config file traversing in 1.3. cfg.vars(config_file_name) is coming.
Back to top Go down
http://sveark.info/ac
Baruch

Baruch


Messages : 105
Joined/Date d'inscription : 2012-08-04
Age : 32
Location/Localisation : France

Gema stats
farthest jump:

Loading a .cfg database Empty
PostSubject: Re: Loading a .cfg database   Loading a .cfg database EmptyWed Sep 05, 2012 10:55 am

Is there any solution to modify a line in a .cfg file in a O(1) complexity ? (without using cfg.setvalue)
Does the cfg.setvalue function goes through all the file until it finds the right index ?
Back to top Go down
Sponsored content





Loading a .cfg database Empty
PostSubject: Re: Loading a .cfg database   Loading a .cfg database Empty

Back to top Go down
 
Loading a .cfg database
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
gema :: International :: Lua-
Jump to: