AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Keyvalues (https://forums.alliedmods.net/showthread.php?t=195333)

marquezs 09-06-2012 10:52

Keyvalues
 
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

Hunter S. Thompson 09-06-2012 10:54

Re: Keyvalues
 
KvGetString(KV, "name", sVa, sizeof(sVa));

You forgot the l, my friend.

marquezs 09-06-2012 10:57

Re: Keyvalues
 
still doesn't work

Hunter S. Thompson 09-06-2012 10:59

Re: Keyvalues
 
/configs/test.cfg

Maybe? I'm not too sure, I'm also having problems with KeyValues.

Peace-Maker 09-06-2012 11:09

Re: Keyvalues
 
You need to call KvGotoFirstSubKey first.

and don't forget to CloseHandle the KV Handle after you're done ;)

marquezs 09-06-2012 11:57

Re: Keyvalues
 
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 :(

Powerlord 09-06-2012 12:05

Re: Keyvalues
 
Code:

"Test"
{
    "name" "jesus"
}

Quote:

Originally Posted by Peace-Maker (Post 1792742)
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...

marquezs 09-06-2012 12:14

Re: Keyvalues
 
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


All times are GMT -4. The time now is 12:52.

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