Raised This Month: $32 Target: $400
 8% 

Solved JumpToKey with path in KeyValues


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
EmeraldGhost
Junior Member
Join Date: Oct 2015
Old 01-31-2021 , 01:10   JumpToKey with path in KeyValues
Reply With Quote #1

Hi alliedmodders, im writing an auto config generator thesedays. but i ran into a problem.
If I use kv.JumpToKey with a path (e.g. props/de_inferno/goldfish), it comes out with these:
Quote:
"props"
{
"de_inferno"
{
"goldfish"
{
"name" "props/de_inferno/goldfish"
"weight" "10"
"hp" "100"
"speed" "1.000000"
"gravity" "1.000000"
}
}
}
but the result I expected is sth like this:
Quote:
"props/de_inferno/goldfish"
{
"name" "props/de_inferno/goldfish"
"weight" "10"
"hp" "100"
"speed" "1.000000"
"gravity" "1.000000"
}
Is there an easy solotion to fix this?
__________________
aka. EmeraldGhost / eeeeeG ^^

Last edited by EmeraldGhost; 01-31-2021 at 04:09.
EmeraldGhost is offline
FAQU
Member
Join Date: Sep 2020
Location: Romania
Old 01-31-2021 , 02:40   Re: JumpToKey with path in KeyValues
Reply With Quote #2

This should do the trick:
PHP Code:
KeyValues kv = new KeyValues("Something");
    
char filepath[PLATFORM_MAX_PATH]; 
BuildPath(Path_SMfilepathsizeof(filepath), "configs/something.cfg");
    
kv.ImportFromFile(filepath);
    
kv.JumpToKey("something"true);
kv.SetSectionName("props/de_inferno/goldfish");
    
kv.SetString("name""props/de_inferno/goldfish");
kv.SetString("weight""10");
kv.SetString("hp""100");
kv.SetString("speed",    "1.000000");
kv.SetString("gravity""1.000000");
    
kv.Rewind();
kv.ExportToFile(filepath);
    
delete kv
Output file:
Code:
"Something"
{
	"props/de_inferno/goldfish"
	{
		"name"		"props/de_inferno/goldfish"
		"weight"	"10"
		"hp"		"100"
		"speed"		"1.000000"
		"gravity"	"1.000000"
	}
}
__________________

Last edited by FAQU; 01-31-2021 at 02:42.
FAQU is offline
EmeraldGhost
Junior Member
Join Date: Oct 2015
Old 01-31-2021 , 04:09   Re: JumpToKey with path in KeyValues
Reply With Quote #3

Quote:
Originally Posted by FAQU View Post
This should do the trick:
PHP Code:
KeyValues kv = new KeyValues("Something");
    
char filepath[PLATFORM_MAX_PATH]; 
BuildPath(Path_SMfilepathsizeof(filepath), "configs/something.cfg");
    
kv.ImportFromFile(filepath);
    
kv.JumpToKey("something"true);
kv.SetSectionName("props/de_inferno/goldfish");
    
kv.SetString("name""props/de_inferno/goldfish");
kv.SetString("weight""10");
kv.SetString("hp""100");
kv.SetString("speed",    "1.000000");
kv.SetString("gravity""1.000000");
    
kv.Rewind();
kv.ExportToFile(filepath);
    
delete kv
Output file:
Code:
"Something"
{
	"props/de_inferno/goldfish"
	{
		"name"		"props/de_inferno/goldfish"
		"weight"	"10"
		"hp"		"100"
		"speed"		"1.000000"
		"gravity"	"1.000000"
	}
}
It works! Thank you!
__________________
aka. EmeraldGhost / eeeeeG ^^
EmeraldGhost 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 21:47.


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