AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Doesn't load nvault data (https://forums.alliedmods.net/showthread.php?t=275568)

~Ice*shOt 12-03-2015 11:16

Doesn't load nvault data
 
Need help, how to make load points with loop? Without loop they are loading fine.
PHP Code:

Load_DataiPlayer )
{
    new 
szKey64 ];
    new 
szData64 ];

    
formatexszKeycharsmaxszKey ), "%s"g_szAuthIDiPlayer ] );

    
//for( new i = 0; i < g_iTotal; i++ )
    //    formatex( szData, charsmax( szData ), "%d", g_iPoints[ iPlayer ] );

    
nvault_getg_iVaultszKeyszDatacharsmaxszData ) );

    new 
szPoints];

    
parseszDataszPointscharsmaxszPoints ) );
    
    for( new 
0g_iTotali++ )
    {
        
g_iPointsiPlayer ][ ] = str_to_numszPoints );
        
log_amx"%d "g_iPointsiPlayer ][ ] );
    }




PartialCloning 12-03-2015 17:06

Re: Doesn't load nvault data
 
1. What is g_iTotal? Where do you set its value?
2. What does the log print out?

ironskillz1 12-03-2015 17:13

Re: Doesn't load nvault data
 
Quote:

Originally Posted by ~Ice*shOt (Post 2368456)
Need help, how to make load points with loop? Without loop they are loading fine.
PHP Code:

Load_DataiPlayer )
{
    new 
szKey64 ];
    new 
szData64 ];

    
formatexszKeycharsmaxszKey ), "%s"g_szAuthIDiPlayer ] );

    
//for( new i = 0; i < g_iTotal; i++ )
    //    formatex( szData, charsmax( szData ), "%d", g_iPoints[ iPlayer ] );

    
nvault_getg_iVaultszKeyszDatacharsmaxszData ) );

    new 
szPoints];

    
parseszDataszPointscharsmaxszPoints ) );
    
    for( new 
0g_iTotali++ )
    {
        
g_iPointsiPlayer ][ ] = str_to_numszPoints );
        
log_amx"%d "g_iPointsiPlayer ][ ] );
    }




Why are you trying to load points with a loop.

Tell us instead what you are trying todo and we can help you easier

Bugsy 12-03-2015 18:49

Re: Doesn't load nvault data
 
You shouldn't post code without including all variables that are referenced. You should also include more information about what you are trying to do.

"how to make load points with loop? Without loop they are loading fine."

How many items are stored in each vault entry?
Is g_iPoints a 2-dimensional array and sized large enough?
What is the value of g_iTotal?

You should make sure g_iTotal is a constant variable and that its value is never larger than the size of the second dimension of g_iPoints or else you can run into index out of bounds errors.

~Ice*shOt 12-04-2015 06:15

Re: Doesn't load nvault data
 
Saving works fine, for example I set points g_iPoints[ iPlayer ][ 3 ] it printout

Quote:

L 12/03/2015 - 18:13:14: [test.amxx] 0
L 12/03/2015 - 18:13:14: [test.amxx] 0
L 12/03/2015 - 18:13:14: [test.amxx] 0
L 12/03/2015 - 18:13:14: [test.amxx] 200
L 12/03/2015 - 18:13:14: [test.amxx] 0
but when it's loading it printout

Quote:

L 12/03/2015 - 18:13:14: [test.amxx] 0
L 12/03/2015 - 18:13:14: [test.amxx] 0
L 12/03/2015 - 18:13:14: [test.amxx] 0
L 12/03/2015 - 18:13:14: [test.amxx] 0
L 12/03/2015 - 18:13:14: [test.amxx] 0
g_iTotal value is always 5.

PHP Code:

new g_iTotal;

new 
g_iPoints[33][5];

public 
native_registeriPluginiParams )
{
    new 
eDataData ];

    
get_string1eDataName ], charsmaxeDataName ] ) );

    
eDataCost ] = get_param);

    
ArrayPushArrayg_aDataeData );
    
g_iTotal++;

    return ( 
g_iTotal );
}

Save_DataiPlayer )
{
    new 
szKey64 ];
    new 
szData64 ];

    
formatexszKeycharsmaxszKey ), "%s"g_szAuthIDiPlayer ] );

    for( new 
0g_iTotali++ )
    {
        
formatexszDatacharsmaxszData ), "%d"g_iPointsiPlayer ][ ] );

        
log_amx"%d"g_iPointsiPlayer ][ ] );
    }

    
nvault_setg_iVaultszKeyszData );


P.S. no errors, nothing.

Bugsy 12-04-2015 07:38

Re: Doesn't load nvault data
 
In your save, try "%d " instead of "%d". How else is parse supposed to know where numbers are separate? Your load function also needs to be fixed

jimaway 12-04-2015 09:12

Re: Doesn't load nvault data
 
you overwrite szData in the for loop with every iteration.
when you use nvault_set only the last value is present in there.

Bugsy 12-04-2015 10:39

Re: Doesn't load nvault data
 
PHP Code:

new iPos

iPos 
+= formatexszDataiPos ] , charsmaxszData ) - iPos "%d "g_iPointsiPlayer ][ ] ); 

You need to do something like this, with iPos defined outside of the loop. You also need to fix your load function

Bugsy 12-04-2015 21:31

Re: Doesn't load nvault data
 
PHP Code:

Save_DataiPlayer )
{
    new 
szData64 ] , iPos;

    
//You do not need to use format for this. You only need to use format when you need to actually format the string.
    //Instead, just pass g_szAuthID[] directly to the nvault native.
    //formatex( szKey, charsmax( szKey ), "%s", g_szAuthID[ iPlayer ] );

    
for( new 0g_iTotali++ )
    {
        
//formatex( szData, charsmax( szData ), "%d", g_iPoints[ iPlayer ][ i ] );
        
iPos += formatexszDataiPos ], charsmaxszData ) - iPos "%d "g_iPointsiPlayer ][ ] );
        
log_amx"%d"g_iPointsiPlayer ][ ] );
    }

    
//nvault_set( g_iVault, szKey, szData );
    
nvault_setg_iVault g_szAuthIDiPlayer ] , szData );
}

Load_DataiPlayer )
{
    new 
szData64 ] , szPts1] , szPts2] , szPts3] , szPts4] , szPts5];

    
nvault_getg_iVaultg_szAuthIDiPlayer ] , szData charsmaxszData ) );

    
parseszData szPts1 charsmaxszPts1 ) , szPts2 charsmaxszPts2 ) , szPts3 charsmaxszPts3 ) , szPts4 charsmaxszPts4 ) , szPts5 charsmaxszPts5 )  );

    
g_iPointsiPlayer ][ ] = str_to_numszPts1 );
    
g_iPointsiPlayer ][ ] = str_to_numszPts2 );
    
g_iPointsiPlayer ][ ] = str_to_numszPts3 );
    
g_iPointsiPlayer ][ ] = str_to_numszPts4 );
    
g_iPointsiPlayer ][ ] = str_to_numszPts5 );



~Ice*shOt 12-05-2015 06:59

Re: Doesn't load nvault data
 
Hey everyone, thanks a lot for your replies and help :)

I made some testing, with this:

PHP Code:

    case 1g_iPointsiPlayer ][ ] += 100;
    case 
2g_iPointsiPlayer ][ ] += 200;
    case 
3g_iPointsiPlayer ][ ] += 300;

Save_DataiPlayer )
{
    new 
szData64 ];

    for( new 
0g_iTotali++ )
    {
        
formatexszDatacharsmaxszData ), "%d"g_iPointsiPlayer ][ ] );

        
log_amx"[%i] %d"ig_iPointsiPlayer ][ ] );
    }

    
nvault_setg_iVaultg_szAuthIDiPlayer ], szData );
}

Load_DataiPlayer )
{
    new 
szData64 ];

    
nvault_getg_iVaultg_szAuthIDiPlayer ], szDatacharsmaxszData ) );

    new  
szPoints];

    
parseszDataszPointscharsmaxszPoints ) );

    for( new 
0g_iTotali++ )
    {
        
g_iPointsiPlayer ][ ] = str_to_numszPoints );
        
log_amx"[%i] %d"ig_iPointsiPlayer ][ ] );
    }


Save:
Quote:

L 12/05/2015 - 13:53:32: [test.amxx] [0] 100
L 12/05/2015 - 13:53:32: [test.amxx] [1] 0
L 12/05/2015 - 13:53:32: [test.amxx] [2] 200
L 12/05/2015 - 13:53:32: [test.amxx] [3] 0
L 12/05/2015 - 13:53:32: [test.amxx] [4] 300
Load:
Quote:

L 12/05/2015 - 13:53:37: [test.amxx] [0] 300
L 12/05/2015 - 13:53:37: [test.amxx] [1] 300
L 12/05/2015 - 13:53:37: [test.amxx] [2] 300
L 12/05/2015 - 13:53:37: [test.amxx] [3] 300
L 12/05/2015 - 13:53:37: [test.amxx] [4] 300
So I would be grateful if we done it in my way, can anyone fix load function? It loads only last element how we see.


All times are GMT -4. The time now is 18:13.

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