Raised This Month: $51 Target: $400
 12% 

KeyValues


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Hunter S. Thompson
Senior Member
Join Date: Jun 2012
Old 09-06-2012 , 09:21   KeyValues
Reply With Quote #1

I'm trying to code a credit system for a JailBreak server; and I've got to use KeyValues, due to the fact that they do not give you a MySQL database, or SQLite, so I'm forced to.

I'm getting tag mismatch warnings, and an error stating that I cannot do the following:
Code:
KvGetString(kv, "credits", credits[client], 1000); <= Warning
KvSetString(kv, "credits", credits[client], 1000); <= Error
Credits is a string, so shouldn't I be able to use it as a string, just with that array so I know I'm passing the correct clients information into that clients credits?
Hunter S. Thompson is offline
mcpan313
Senior Member
Join Date: Mar 2010
Old 09-06-2012 , 09:34   Re: KeyValues
Reply With Quote #2

Example:
PHP Code:
decl String:buffer[32];
// if "credits" not found, buffer = "defvalue"
KvGetString(kv"credits"buffersizeof(buffer), "defvalue");

KvSetString(kv"credits"buffer); 
see
http://docs.sourcemod.net/api/index....d=show&id=269&
http://docs.sourcemod.net/api/index....d=show&id=264&
__________________
sorry, for my poor english.
mcpan313 is offline
Send a message via MSN to mcpan313
Hunter S. Thompson
Senior Member
Join Date: Jun 2012
Old 09-06-2012 , 09:42   Re: KeyValues
Reply With Quote #3

Quote:
Originally Posted by mcpan313 View Post
Example:
PHP Code:
decl String:buffer[32];
// if "credits" not found, buffer = "defvalue"
KvGetString(kv"credits"buffersizeof(buffer), "defvalue");

KvSetString(kv"credits"buffer); 
see
http://docs.sourcemod.net/api/index....d=show&id=269&
http://docs.sourcemod.net/api/index....d=show&id=264&
Hmm. I'm not seeing a way to copy the clients credits to a temp string, or use said credits[client].

Would using credits without the credits[client] work for the maxsize?
Hunter S. Thompson is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 09-06-2012 , 09:45   Re: KeyValues
Reply With Quote #4

Quote:
Originally Posted by Hunter S. Thompson View Post
Hmm. I'm not seeing a way to copy the clients credits to a temp string, or use said credits[client].

Would using credits without the credits[client] work for the maxsize?
is credits[client] a string or an int?
Mitchell is offline
Hunter S. Thompson
Senior Member
Join Date: Jun 2012
Old 09-06-2012 , 09:46   Re: KeyValues
Reply With Quote #5

Quote:
Originally Posted by Mitchell View Post
is credits[client] a string or an int?
It's a string; I was just going to use StringToInt when needed to increment or decrement.
Hunter S. Thompson is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 09-06-2012 , 09:57   Re: KeyValues
Reply With Quote #6

OK, better question: Why is credits[client] a String and not an int?

If you're trying to save space, "1000" is a 5 character (and thus 5 byte) String (due to the nul terminator), while all numbers in Pawn are 4 bytes.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 09-06-2012 at 09:59.
Powerlord is offline
Hunter S. Thompson
Senior Member
Join Date: Jun 2012
Old 09-06-2012 , 10:05   Re: KeyValues
Reply With Quote #7

Quote:
Originally Posted by Powerlord View Post
OK, better question: Why is credits[client] a String and not an int?

If you're trying to save space, "1000" is a 5 character (and thus 5 byte) String (due to the nul terminator), while all numbers in Pawn are 4 bytes.
Because of the KeyValues, I thought it was necessary to be a string, instead of an integer.

Edit: Oh wait, my bad. It is an int. So it needs to be a string.

Edit 2: Yeah, that was my bad. It's all good, thanks for your help, guys.

Last edited by Hunter S. Thompson; 09-06-2012 at 10:07.
Hunter S. Thompson is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 09-06-2012 , 10:11   Re: KeyValues
Reply With Quote #8

In KeyValues, Keys need to be Strings. Values can be int, String, Float, Color, or Vector. No idea what Color is, though.

Side note: Values are still stored as Strings, Valve just has code to store and retrieve them as other data types.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
Hunter S. Thompson
Senior Member
Join Date: Jun 2012
Old 09-06-2012 , 10:13   Re: KeyValues
Reply With Quote #9

Quote:
Originally Posted by Powerlord View Post
In KeyValues, Keys need to be Strings. Values can be int, String, Float, Color, or Vector. No idea what Color is, though.

Side note: Values are still stored as Strings, Valve just has code to store and retrieve them as other data types.
Right, so I'd use IntToString, and StringToInt when I load it, right?

Why are they stored as strings? That seems like a misuse of storage space, as an int is only 1 byte when it's under 9.
Hunter S. Thompson is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 09-06-2012 , 10:14   Re: KeyValues
Reply With Quote #10

Quote:
Originally Posted by Powerlord View Post
In KeyValues, Keys need to be Strings. Values can be int, String, Float, Color, or Vector. No idea what Color is, though.

Side note: Values are still stored as Strings, Valve just has code to store and retrieve them as other data types.
Color is like vector but saves 4 values inside it instead.
Mitchell is offline
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 04:17.


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