AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Load ini [Lines] (https://forums.alliedmods.net/showthread.php?t=136069)

mottzi 08-22-2010 13:38

Load ini [Lines]
 
Hello,

Can anybody show me, how to read all lines of a Ini file? Like:

HTML Code:

de_dust2
de_dust
de_train


so i have, as example, all maps in one array? (new file[][])

fysiks 08-22-2010 14:25

Re: Load ini [Lines]
 
There are several examples. You can look at my Bot Apology plugin shown in my signature.

Vechta 08-22-2010 14:50

Re: Load ini [Lines]
 
Maybe you can make a little tutorial how it exactly work ?

fysiks 08-22-2010 15:07

Re: Load ini [Lines]
 
Quote:

Originally Posted by Vechta (Post 1278986)
Maybe you can make a little tutorial how it exactly work ?

It's an extremely simple example already. There is not a whole lot to explain.

Mxnn 08-22-2010 17:34

Re: Load ini [Lines]
 
You can read this way:
PHP Code:

new linecharcount
new data[128]
while ((
line = (read_file("file.ini"linedatacharsmax(data), charcount))))
    {
        
read_file("file.ini"linedatacharsmax(data), charcount)
        
//Asks
    


The code will read the file until the end of file.
In //Asks you can ask if the line is "de_dust" or that.

Parameters:
line represents the number line
charcount the char count of the line
data, content the line (ej: de_dust2)

fysiks 08-22-2010 17:41

Re: Load ini [Lines]
 
Quote:

Originally Posted by Mxnn (Post 1279127)
You can read this way:
PHP Code:

new linecharcount
new data[128]
while ((
line = (read_file("file.ini"linedatacharsmax(data), charcount))))
    {
        
read_file("file.ini"linedatacharsmax(data), charcount)
        
//Asks
    


The code will read the file until the end of file.
In //Asks you can ask if the line is "de_dust" or that.

Parameters:
line represents the number line
charcount the char count of the line
data, content the line (ej: de_dust2)

Nobody should use this. Use the method shown in my plugin.

nikhilgupta345 08-22-2010 22:06

Re: Load ini [Lines]
 
fysiks i got a question about your plugin? It says in one of the parameters for fgets, sizeof(data)-1. Would it be better to use charsmax? If not, why would you use sizeof there instead of charsmax?

Or, would they both work?

fysiks 08-22-2010 22:42

Re: Load ini [Lines]
 
Quote:

Originally Posted by nikhilgupta345 (Post 1279353)
fysiks i got a question about your plugin? It says in one of the parameters for fgets, sizeof(data)-1. Would it be better to use charsmax? If not, why would you use sizeof there instead of charsmax?

Or, would they both work?

charsmax = sizeof - 1

So, it's the same thing. That was before I knew about charsmax.

nikhilgupta345 08-22-2010 23:22

Re: Load ini [Lines]
 
Ok, thanks, just wondering if there were special cases when u would use one and not the other.

fysiks 08-22-2010 23:25

Re: Load ini [Lines]
 
Quote:

Originally Posted by nikhilgupta345 (Post 1279391)
Ok, thanks, just wondering if there were special cases when u would use one and not the other.

I always use charsmax for strings now. Bugsy explained it nicely recently in another thread.


All times are GMT -4. The time now is 21:58.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.