SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Help Archive

 
 
Thread Tools Display Modes
Old 18/10/2010, 03:55 AM   #1
[SOB]Chris
Big Clucker
 
Join Date: Jul 2009
Posts: 91
Reputation: 0
Post Yini reading Example

Hi, Every One.
I just want a example for how to use the (Yini Inc) for reading .ini
I have a ini file in the nex path
Code:
scriptfiles/example/test.ini
and the ini contains
Code:
testkey = 1
how i can read the test key and store his value in a varible using yini.
Thanks.
[SOB]Chris is offline  
Old 18/10/2010, 02:59 PM   #2
[SOB]Chris
Big Clucker
 
Join Date: Jul 2009
Posts: 91
Reputation: 0
Default Respuesta: Yini reading Example

Someone plz.
Thanks.
[SOB]Chris is offline  
Old 18/10/2010, 03:25 PM   #3
LarzI
High-roller
 
LarzI's Avatar
 
Join Date: Apr 2007
Location: Norway
Posts: 3,554
Reputation: 130
Default Re: Yini reading Example

Quote:
Originally Posted by Y_Less View Post
Reading

This system differs in use quite significantly from dini, but with good reason. In dini you open a file, search for a single value, read that value, close the file and repeat. Imagine this code:

pawn Code:
gA = dini_Get("myini.ini", "c");
gB = dini_Get("myini.ini", "b");
gC = dini_Get("myini.ini", "a");

And this ini file:

Code:
a = 10
b = 67
c = 42
If you can't tell that will open and close the file 3 times and read 6 lines in, just for 3 values - surely you should just open the file once and read 3 lines? This is the equivalent y_ini code:

pawn Code:
INI:myini[](name[], value[])
{
    INI_String("a", gA);
    INI_String("b", gB);
    INI_String("c", gC);
}

pawn Code:
INI_Load("myini.ini");

The code is a little longer, but it's much faster, only reading the file once. Esentially y_ini uses callbacks to load files instead of explicitly reading individual values, which means files are read in the order they are stored. I intend to add the option to load individual values later, but there's rarely any need if you do things properly - read a file and get the data, it's not going to change unless you change it.
<eight.>
__________________


NEW: [FS] Simple Cellphones

if( strfind( title, "REP", true ) != -1 )
{________________________________________
Sigh();__________________________
}________________________________________


LarzI is offline  
Old 18/10/2010, 03:27 PM   #4
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 18,316
Reputation: 2579
Default Re: Yini reading Example

pawn Code:
INI:test[](name[], value[])
{
    if (!strcmp(name, "testkey"))
    {
        gSaveVar = strval(value);
    }
}

pawn Code:
INI_Load("example\test.ini");
Y_Less is online now  
Old 19/10/2010, 02:23 AM   #5
[SOB]Chris
Big Clucker
 
Join Date: Jul 2009
Posts: 91
Reputation: 0
Default Respuesta: Yini reading Example

damn here is my code
pawn Code:
new pAKA[128];
        INI_Load("ladmin/config/aka.txt");
        INI:aka[](name[], value[])
        {
            if (!strcmp(name, "tmp3"))
            {
                pAKA = value;
            }
        }
i try this to
pawn Code:
new pAKA[128];
        INI_Load("ladmin/config/aka.txt");
        INI:aka[](name[], value[])
        {

            INI_String("tmp3", pAKA);
        }
but the compiler send me this erros, wtfail im doing wrong? sorry for be to newbie u.u
Code:
.pwn(725) : error 029: invalid expression, assumed zero
.pwn(725) : error 017: undefined symbol "@INI_aka_"
.pwn(725) : error 017: undefined symbol "@INI_aka_"
.pwn(725) : fatal error 107: too many error messages on one line
[SOB]Chris is offline  
Old 19/10/2010, 02:26 AM   #6
MrDeath537
High-roller
 
Join Date: Nov 2009
Location: Argentina
Posts: 2,082
Reputation: 29
Default Respuesta: Yini reading Example

Quote:
Originally Posted by [SOB]Chris View Post
damn here is my code
pawn Code:
new pAKA[128];
        INI_Load("ladmin/config/aka.txt");
        INI:aka[](name[], value[])
        {
            if (!strcmp(name, "tmp3"))
            {
                pAKA = value;
            }
        }
i try this to
pawn Code:
new pAKA[128];
        INI_Load("ladmin/config/aka.txt");
        INI:aka[](name[], value[])
        {

            INI_String("tmp3", pAKA);
        }
but the compiler send me this erros, wtfail im doing wrong? sorry for be to newbie u.u
Code:
.pwn(725) : error 029: invalid expression, assumed zero
.pwn(725) : error 017: undefined symbol "@INI_aka_"
.pwn(725) : error 017: undefined symbol "@INI_aka_"
.pwn(725) : fatal error 107: too many error messages on one line
Try it:
pawn Code:
new pAKA[128];
                INI:aka[](name[], value[])
        {
                    if (!strcmp(name, "tmp3"))
                    {
                        pAKA = value;
                }
                }

        INI_Load("ladmin/config/aka.txt");
__________________
Trabajando en 3 includes, ny_INI, ny_XML y ny_Handling.
MrDeath537 is offline  
Old 19/10/2010, 02:33 AM   #7
[SOB]Chris
Big Clucker
 
Join Date: Jul 2009
Posts: 91
Reputation: 0
Default Respuesta: Yini reading Example

pawn Code:
new pAKA[128];
        INI:aka[](name[], value[])
        {
            if (!strcmp(name, "tmp3"))
            {
                pAKA = value;
            }
        }
        INI_Load("ladmin/config/aka.txt");
send the same error just in diferent line haha, i missed something?
Code:
.pwn(725) : error 029: invalid expression, assumed zero
.pwn(725) : error 017: undefined symbol "@INI_aka_"
.pwn(725) : error 017: undefined symbol "@INI_aka_"
.pwn(725) : fatal error 107: too many error messages on one line
[SOB]Chris is offline  
Old 19/10/2010, 08:57 AM   #8
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 18,316
Reputation: 2579
Default Re: Yini reading Example

aka is a function, you seem to be putting it inline with other code.
Y_Less is online now  
Old 22/10/2010, 03:42 AM   #9
[SOB]Chris
Big Clucker
 
Join Date: Jul 2009
Posts: 91
Reputation: 0
Default Respuesta: Yini reading Example

i see then i need to use global variables for my sistems =S?
[SOB]Chris is offline  
Old 22/10/2010, 09:04 AM   #10
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 18,316
Reputation: 2579
Default Re: Yini reading Example

Yes, or you can also use function calls such as SetPlayerHealth in that callback (obviously if your ini contains data on health for example).
Y_Less is online now  
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading directory regdude Help Archive 3 29/08/2010 08:31 PM
Reading a timer (.Aztec); Help Archive 0 08/08/2010 11:54 PM
Reading from a file LeePL Help Archive 1 12/08/2009 07:01 PM
Error reading from ini Vince Help Archive 2 05/04/2009 08:29 AM
Reading SQL ID Coicatak Help Archive 0 04/02/2009 11:15 AM


All times are GMT. The time now is 10:33 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.