Raised This Month: $4 Target: $400
 1% 

String to KeyValues


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 11-15-2013 , 10:43   String to KeyValues
Reply With Quote #1

Ciao,

is there any possibility how to convert string to KeyValues tree? I need something like:

PHP Code:
// example inspired by https://wiki.alliedmods.net/KeyValues_(SourceMod_Scripting)#Basic_Lookup

new String:MyDataString[256] = "\"MyStructure\"{ \"STEAM_0:0:7\"{ \"name\" \"crab\"} }";
.
.
.
.
GetNameFromSteamIDPlayerSteamIDPlayerName32MyDataString ); // PlayerSteamID and PlayerName are just for example
.
.
.
.
bool:GetNameFromSteamID(const String:steamid[], String:name[], maxlengthString:DataString[])
{
    new 
Handle:kv CreateKeyValues("MyStructure");

    
StringToKeyValues(kvDataString); // need this function

    
if (!KvJumpToKey(kvsteamid))
    {
        return 
false;
    }
    
KvGetString(kv"name"namemaxlength);
    
CloseHandle(kv);
    return 
true;

I don't wanna make a new file with KeyValues structure and then convert this file to KeyValues. I wanna make string (e.g. pass throw function argument) ang this string convert to KeyValues.

Last edited by KissLick; 11-15-2013 at 11:37.
KissLick is offline
GsiX
gee, six eggs
Join Date: Aug 2012
Location: Land Below The Wind
Old 11-15-2013 , 11:27   Re: String to KeyValues
Reply With Quote #2

You were saying something like this, yes??

Code:
"MyStructure"
{
	"STEAM_0:0:0000"
	{
		"name"	"On_my_crab"
	}
	
	// or
	
	"LickMe_KickYou"
	{
		"SteamID"	"STEAM_0:0:0000"
		"name"		"Oh_my_crab"
	}
}

and this one should be..
PHP Code:
if (!KvJumpToKey(kvsteamid))
{
    
CloseHandle(kv);
    return 
false;

__________________
If i happen to insulted you unintentionally,
it was me and Google Translate who did it.

Last edited by GsiX; 11-15-2013 at 11:28.
GsiX is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 11-15-2013 , 11:36   Re: String to KeyValues
Reply With Quote #3

No, that was just an example (with mistake copied from SM wiki :-D ). The main thing I need is function
PHP Code:
StringToKeyValues(kvDataString); 
Because I don't wanna make KeyValues from file but from string. Now I found json https://forums.alliedmods.net/showth...highlight=json do you think that use json is better solution than KeyValues?

Last edited by KissLick; 11-15-2013 at 11:36.
KissLick is offline
GsiX
gee, six eggs
Join Date: Aug 2012
Location: Land Below The Wind
Old 11-15-2013 , 11:49   Re: String to KeyValues
Reply With Quote #4

As far as i concern, keyValue is string.
Why you want "StringToString"?

EDIT: Pardon my poor english but i don't realy understand it.
__________________
If i happen to insulted you unintentionally,
it was me and Google Translate who did it.

Last edited by GsiX; 11-15-2013 at 11:50.
GsiX is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 11-15-2013 , 12:04   Re: String to KeyValues
Reply With Quote #5

Well, I don't mean KeyValues like string but like KeyValues tree. I just wanna iterate throw the KeyValues tree via function KvGotoNextKey(kv) etc. and only function to get existed KeyValues structure is via FileToKeyValues(kv, "myfile.txt") but I wanna use string instead of file.

So what I want is

PHP Code:
new Handle:kv CreateKeyValues("MyStructure");
StringToKeyValues(kvDataString); 
and then

PHP Code:
do
{
// code
} while (KvGotoNextKey(kv)); 
I want this to pass KeyValues between functions. One function make a string and another function process this KeyValues string via function KvGotoNextKey(kv).

Now i think use json is better that KeyValues, but I am not sure..
KissLick is offline
GsiX
gee, six eggs
Join Date: Aug 2012
Location: Land Below The Wind
Old 11-15-2013 , 13:16   Re: String to KeyValues
Reply With Quote #6

PHP Code:
StringToKeyValuesHandle:Kv, const String:SAVEPath[], const String:DataString[], const String:Buff[]  )
{
    
decl String:Value[32][128];
    
FileToKeyValuesKvSAVEPath );
    
KvGotoFirstSubKeyKvfalse );
    
    new 
i;
    do
    {
        
KvGetSectionNameKvValue[i], 15 );
        
i++;
    }
    while ( 
KvGotoNextKeyKv,false ));
    
KvRewindKv );
    
    
// retriv data from keyvalue. Maybe what you looking for
    
KvJumpToKeyKvDataStringfalse);
    
KvGetStringKvValue[0], BuffsizeofBuff ), "Null" );
    
KvRewindKv );

I fail..
__________________
If i happen to insulted you unintentionally,
it was me and Google Translate who did it.
GsiX is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 11-15-2013 , 13:37   Re: String to KeyValues
Reply With Quote #7

Well.. I decided to do it via json.. it looks easier :-D

Anyway, thanks for help ;-)
KissLick 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:03.


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