Thread: nVault Tutorial
View Single Post
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-24-2016 , 10:45   Re: nVault Tutorial
Reply With Quote #86

With your code, Black Rose, it will appear to work correctly to users while in reality it is not.

It is storing the data in nVault with a single character as the key because it is using the right-most byte in the cell as the ascii character since it is expecting a string (which is normal for how Pawn stores/interprets strings).

PHP Code:
public client_authorizedid 
{
    
//Lets pretend my SteamID 'value' is 2298457
    
giSteamIDid ][ ] = 2298457 //GetUseriSteamID( id );
    
gPointsid ] = nvault_getg_Vault giSteamIDid ] )
    
    
//Print the key as both an integer as string.
    
server_print"nvault_get : [%d] [%s]" giSteamIDid ] , giSteamIDid ] );

Output
Code:
nvault_get : [2298457] [Y]
steam id integer = 2298457
char 'Y' ascii val = 89

In binary:
2298457 = 0000 0000 0010 0011 0001 0010 0101 1001
0000089 = 0000 0000 0000 0000 0000 0000 0101 1001

So when passing a cell holding 2298457, Pawn is taking the right-most byte value of 89 and say's oh ok, this means character 'Y' is the key.



I know you already acknowledged this issue, but for anyone that may have tried your code and saw it working, I wanted to explain it more because it should not be used.

Even with SQL, wouldn't you still need to convert it to a string in your SQL query? I think this would be useful in some type of hash lookup table where it takes an integer value as the input.
__________________

Last edited by Bugsy; 09-24-2016 at 10:48.
Bugsy is offline