AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Load & Save bool problem (https://forums.alliedmods.net/showthread.php?t=219927)

Napoleon_be 07-04-2013 20:30

Load & Save bool problem
 
I'm trying to save 2 booleans, but i'm getting 2 warnings and i know i'm doing something wrong but i can't figure out how i should save / load a bool. Someone help me?

iDoublePoints[33]
and
isVIP[33]
are the bools.
code:

PHP Code:

public SaveData(id) {
    new 
SteamID[32]
    
get_user_authid(idSteamIDcharsmax(SteamID))
    
    new 
vaultkey[64], vaultdata[256]
    
    
format(vaultkeycharsmax(vaultkey), "%s-POINTSYSTEM"SteamID)
    
format(vaultdatacharsmax(vaultdata), "%i#%i#%i#"iPoints[id], iDoublePoints[id], isVIP[id])
    
nvault_set(gVaultvaultkeyvaultdata)
    return 
PLUGIN_CONTINUE
}

public 
LoadData(id) {
    new 
SteamID[32]
    
get_user_authid(idSteamIDcharsmax(SteamID))
    
    new 
vaultkey[64], vaultdata[256]
    
    
format(vaultkeycharsmax(vaultkey), "%s-POINTSYSTEM"SteamID)
    
format(vaultdatacharsmax(vaultdata), "%i#%i#%i#"iPoints[id], iDoublePoints[id], isVIP[id])
    
nvault_get(gVaultvaultkeyvaultdatacharsmax(vaultdata))
    
    
replace_all(vaultdatacharsmax(vaultdata), "#"" ")
    
    new 
points[32], doublepoints[32], vip[32]
    
    
parse(vaultdatapointscharsmax(points), doublepointscharsmax(doublepoints), vipcharsmax(vip))
    
    
iPoints[id] = str_to_num(points)
    
iDoublePoints[id] = str_to_num(doublepoints)
    
isVIP[id] = str_to_num(vip)
    
    return 
PLUGIN_CONTINUE



^SmileY 07-04-2013 20:59

Re: Load & Save bool problem
 
You need to save as number if you want to use a %i chars, but if you want to save as boolean,

try on both

PHP Code:

format(vaultdatacharsmax(vaultdata), "%i#%i#%i#"iPoints[id], iDoublePoints[id] ? 0isVIP[id] ? 0); 


Napoleon_be 07-04-2013 22:07

Re: Load & Save bool problem
 
the problem is, i'm getting tag mismatches on those lines:

PHP Code:

iDoublePoints[id] = str_to_num(doublepoints)
isVIP[id] = str_to_num(vip

and i don't care if it's saved & loaded as numbers, i just want em to be saved and loaded no matter how :p

^SmileY 07-04-2013 22:23

Re: Load & Save bool problem
 
It's the same case, an boolean value is not a string LOL its a single value.

PHP Code:

    iDoublePoints[id] = str_to_num(doublepoints)
    
isVIP[id] = str_to_num(vip

>

</span></span>
PHP Code:

    iDoublePoints[id] = str_to_num(doublepoints) ? true false
    isVIP
[id] = str_to_num(vip) ? true false 


fysiks 07-05-2013 00:04

Re: Load & Save bool problem
 
Quote:

Originally Posted by ^SmileY (Post 1983557)
It's the same case, an boolean value is not a string LOL its a single value.

PHP Code:

    iDoublePoints[id] = str_to_num(doublepoints)
    
isVIP[id] = str_to_num(vip

>

</span></span>
PHP Code:

    iDoublePoints[id] = str_to_num(doublepoints) ? true false
    isVIP
[id] = str_to_num(vip) ? true false 


OR

Code:

        iDoublePoints[id] = bool:!!str_to_num(doublepoints)
        isVIP[id] = bool:!!str_to_num(vip)


ConnorMcLeod 07-05-2013 00:41

Re: Load & Save bool problem
 
I don't understand why people use # in vault datas, spaces are perfectly fine.
Seems you used a code posted a long time ago.

About functions, i think they don't need to be public, vaultdata array doesn't need to be so large, in LoadData you don't need to format data before retrieve it, and formatex can be used instead of format.

About your question, either use !!, either use bool tag :

PHP Code:

SaveData(id)
{
    new 
SteamID[32], vaultkey[64], vaultdata[32];

    
get_user_authid(idSteamIDcharsmax(SteamID));

    
formatex(vaultkeycharsmax(vaultkey), "%s-POINTSYSTEM"SteamID);
    
formatex(vaultdatacharsmax(vaultdata), "%i %i %i"iPoints[id], iDoublePoints[id], isVIP[id]);

    
nvault_set(gVaultvaultkeyvaultdata);
}

LoadData(id)
{
    new 
SteamID[32], vaultkey[64], vaultdata[32], points[12], doublepoints[2], vip[2];

    
get_user_authid(idSteamIDcharsmax(SteamID));

    
formatex(vaultkeycharsmax(vaultkey), "%s-POINTSYSTEM"SteamID);
    
    if( 
nvault_get(gVaultvaultkeyvaultdatacharsmax(vaultdata)) )
    {
        
parse(vaultdatapointscharsmax(points), doublepointscharsmax(doublepoints), vipcharsmax(vip));

        
iPoints[id] = str_to_num(points);
        
iDoublePoints[id] = !!str_to_num(doublepoints);
        
isVIP[id] = bool:str_to_num(vip);
    }
    else
    {
        
iPoints[id] = 0;
        
iDoublePoints[id] = false;
        
isVIP[id] = false;
    }



fysiks 07-05-2013 01:00

Re: Load & Save bool problem
 
Quote:

Originally Posted by ConnorMcLeod (Post 1983608)
use !!, either use bool tag :

I couldn't remember if !! tagged it as a boolean intrinsically.

ConnorMcLeod 07-05-2013 01:10

Re: Load & Save bool problem
 
! is bolean check, so yes :)

Forgot to say that steamid should be enough as vault key, if you need to save other datas, use another vault file :

PHP Code:

public SaveData(id)
{
    new 
SteamID[32], vaultdata[32];

    
get_user_authid(idSteamIDcharsmax(SteamID));

    
formatex(vaultdatacharsmax(vaultdata), "%i %i %i"iPoints[id], iDoublePoints[id], isVIP[id]);

    
nvault_set(gVaultSteamIDvaultdata);
}

public 
LoadData(id)
{
    new 
SteamID[32], vaultdata[32], points[12], doublepoints[2], vip[2];

    
get_user_authid(idSteamIDcharsmax(SteamID));
    
    if(    
nvault_get(gVaultSteamIDvaultdatacharsmax(vaultdata))
    &&    
parse(vaultdatapointscharsmax(points), doublepointscharsmax(doublepoints), vipcharsmax(vip)) == 3    )
    {
        
iPoints[id] = str_to_num(points);
        
iDoublePoints[id] = !!str_to_num(doublepoints);
        
isVIP[id] = bool:str_to_num(vip);
    }
    else
    {
        
iPoints[id] = 0;
        
iDoublePoints[id] = false;
        
isVIP[id] = false;
    }



Napoleon_be 07-05-2013 11:59

Re: Load & Save bool problem
 
Quote:

Originally Posted by ConnorMcLeod (Post 1983626)
! is bolean check, so yes :)

Forgot to say that steamid should be enough as vault key, if you need to save other datas, use another vault file :

PHP Code:

public SaveData(id)
{
    new 
SteamID[32], vaultdata[32];

    
get_user_authid(idSteamIDcharsmax(SteamID));

    
formatex(vaultdatacharsmax(vaultdata), "%i %i %i"iPoints[id], iDoublePoints[id], isVIP[id]);

    
nvault_set(gVaultSteamIDvaultdata);
}

public 
LoadData(id)
{
    new 
SteamID[32], vaultdata[32], points[12], doublepoints[2], vip[2];

    
get_user_authid(idSteamIDcharsmax(SteamID));
    
    if(    
nvault_get(gVaultSteamIDvaultdatacharsmax(vaultdata))
    &&    
parse(vaultdatapointscharsmax(points), doublepointscharsmax(doublepoints), vipcharsmax(vip)) == 3    )
    {
        
iPoints[id] = str_to_num(points);
        
iDoublePoints[id] = !!str_to_num(doublepoints);
        
isVIP[id] = bool:str_to_num(vip);
    }
    else
    {
        
iPoints[id] = 0;
        
iDoublePoints[id] = false;
        
isVIP[id] = false;
    }



Thanks :). I don't know about saving stuff with nvault and mysql, i usualy copy/paste because i don't get the logic in it.


All times are GMT -4. The time now is 06:27.

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