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

Keyvalues


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
marquezs
Member
Join Date: Jun 2010
Old 09-06-2012 , 10:52   Keyvalues
Reply With Quote #1

Hello, I'm trying to get the value of a key, and I've tried many ways and it still doesn't work... there's no errors in the compilation, but I can't get the name of key, when I do a print chat it doesn't show anything.

here my config file


test.cfg
Code:
"Test"
{
	"name" "jesus"
}
function which grabs key value
Code:
public motd(client, target) {

	
    new String:sPath[PLATFORM_MAX_PATH]; 

    BuildPath(Path_SM, sPath, sizeof(sPath), "configs/test.cfg"); 
	
	new String:sVal[64]; 
    if(!FileExists(sPath)) { 
        PrintToChat(client, "Error"); 
        return; 
    } 

    new Handle:KV = CreateKeyValues("Test"); 
    FileToKeyValues(KV, sPath); 


    KvGetString(KV, "name", sVal, sizeof(sVa)); 
    PrintToChat(client, "good to go %s", sVal)
Thanks

Last edited by marquezs; 09-06-2012 at 10:56. Reason: edit: forgot to put an l but the was an issue of copy/paste, in my original code it's ok
marquezs is offline
Hunter S. Thompson
Senior Member
Join Date: Jun 2012
Old 09-06-2012 , 10:54   Re: Keyvalues
Reply With Quote #2

KvGetString(KV, "name", sVa, sizeof(sVa));

You forgot the l, my friend.
Hunter S. Thompson is offline
marquezs
Member
Join Date: Jun 2010
Old 09-06-2012 , 10:57   Re: Keyvalues
Reply With Quote #3

still doesn't work
marquezs is offline
Hunter S. Thompson
Senior Member
Join Date: Jun 2012
Old 09-06-2012 , 10:59   Re: Keyvalues
Reply With Quote #4

/configs/test.cfg

Maybe? I'm not too sure, I'm also having problems with KeyValues.
Hunter S. Thompson is offline
Peace-Maker
SourceMod Plugin Approver
Join Date: Aug 2008
Location: Germany
Old 09-06-2012 , 11:09   Re: Keyvalues
Reply With Quote #5

You need to call KvGotoFirstSubKey first.

and don't forget to CloseHandle the KV Handle after you're done ;)
__________________
Peace-Maker is offline
marquezs
Member
Join Date: Jun 2010
Old 09-06-2012 , 11:57   Re: Keyvalues
Reply With Quote #6

Quote:
public motd(client, target) {


new String:sPath[PLATFORM_MAX_PATH];

BuildPath(Path_SM, sPath, sizeof(sPath), "configs/test.cfg");

new String:sVal[64];
if(!FileExists(sPath)) {
PrintToChat(client, "Error");
return;
}

new Handle:KV = CreateKeyValues("Test");
FileToKeyValues(KV, sPath);

KvGotoFirstSubKey(KV);

KvGetString(KV, "name", sVal, sizeof(sVal));
PrintToChat(client, "good to go %s", sVal)
CloseHandle(KV);
still doesn't work

Last edited by marquezs; 09-06-2012 at 11:57.
marquezs is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 09-06-2012 , 12:05   Re: Keyvalues
Reply With Quote #7

Code:
"Test"
{
    "name" "jesus"
}
Quote:
Originally Posted by Peace-Maker View Post
You need to call KvGotoFirstSubKey first.
KvGotoFirstSubKey without the second argument being set to false will just return false with this structure, as there are no subkeys under the root (only values).

KvGotoFirstSubKey with the second argument being set to false will make
PHP Code:
KvGetString(KV"name"sValsizeof(sVal)); 
return false, as it should since a value doesn't have any values beneath it.

PHP Code:
KvGetString(KVNULL_STRINGsValsizeof(sVal)); 
should work at that point, though.

Still,
PHP Code:
KvGetString(KV"name"sValsizeof(sVal)); 
should work without needing KvGotoFirstSubKey...
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
marquezs
Member
Join Date: Jun 2010
Old 09-06-2012 , 12:14   Re: Keyvalues
Reply With Quote #8

Well, I tested it and it doesn't, I've been looking at this for hours and can't find a way for this to work
marquezs is offline
Reply


Thread Tools
Display Modes

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 14:31.


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