A website for every gema-assaultcube fan
 
HomeHome  CalendarCalendar  FAQFAQ  SearchSearch  MemberlistMemberlist  UsergroupsUsergroups  RegisterRegister  Log in  

Share | 
 

 Loading a .cfg database

View previous topic View next topic Go down 
AuthorMessage
Baruch



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

Gema stats
farthest jump:

PostSubject: Loading a .cfg database   Fri 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
View user profile
Baruch



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

Gema stats
farthest jump:

PostSubject: Re: Loading a .cfg database   Fri 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
View user profile
Baruch



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

Gema stats
farthest jump:

PostSubject: Re: Loading a .cfg database   Fri 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
View user profile
Baruch



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

Gema stats
farthest jump:

PostSubject: Re: Loading a .cfg database   Fri 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
View user profile
Sveark



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

PostSubject: Re: Loading a .cfg database   Sun 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
View user profile http://sveark.info/ac
Baruch



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

Gema stats
farthest jump:

PostSubject: Re: Loading a .cfg database   Wed 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
View user profile
Sponsored content




PostSubject: Re: Loading a .cfg database   Today at 4:33 pm

Back to top Go down
 
Loading a .cfg database
View previous topic View next topic Back to top 
Page 1 of 1
 Similar topics
-
» Loading Lag?
» Loading Invoker's Resources into Game
» Gravity Rush Loading Screens!
» rFactor Database
» Tactic Training Database

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