Raised This Month: $ Target: $400
 0% 

Load & Save bool problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 07-04-2013 , 20:30   Load & Save bool problem
Reply With Quote #1

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

__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 07-04-2013 , 20:59   Re: Load & Save bool problem
Reply With Quote #2

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); 
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 07-04-2013 , 22:07   Re: Load & Save bool problem
Reply With Quote #3

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
__________________

Last edited by Napoleon_be; 07-04-2013 at 22:08.
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 07-04-2013 , 22:23   Re: Load & Save bool problem
Reply With Quote #4

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 
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-05-2013 , 00:04   Re: Load & Save bool problem
Reply With Quote #5

Quote:
Originally Posted by ^SmileY View Post
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)
__________________

Last edited by fysiks; 07-05-2013 at 00:05.
fysiks is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 07-05-2013 , 00:41   Re: Load & Save bool problem
Reply With Quote #6

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;
    }

__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-05-2013 , 01:00   Re: Load & Save bool problem
Reply With Quote #7

Quote:
Originally Posted by ConnorMcLeod View Post
use !!, either use bool tag :
I couldn't remember if !! tagged it as a boolean intrinsically.
__________________
fysiks is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 07-05-2013 , 01:10   Re: Load & Save bool problem
Reply With Quote #8

! 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;
    }

__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 07-05-2013 at 01:13.
ConnorMcLeod is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 07-05-2013 , 11:59   Re: Load & Save bool problem
Reply With Quote #9

Quote:
Originally Posted by ConnorMcLeod View Post
! 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.
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Reply



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

Forum Jump


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


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