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

keyvalues


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Battousai-sama
Veteran Member
Join Date: Jul 2007
Old 04-18-2017 , 17:37   keyvalues
Reply With Quote #1

cant understand keyvalues for the life of me through wiki kv

PHP Code:
"MyFile"
{
    
"general"
    
{
        
"steamid"        "value"
        "steamid"        "value"
        "steamid"        "value"
    
}

i want to get each steamid with its appropriate value saved to a variable
then use a anyfunction(steamid, value) on given steamid from that list
__________________
Battousai-sama is offline
Send a message via MSN to Battousai-sama
B3none
AlliedModders Donor
Join Date: Oct 2016
Location: United Kingdom
Old 04-18-2017 , 18:32   Re: keyvalues
Reply With Quote #2

I'd suggest looking around at other plugins that use KeyValues. You should also have a read of the functions available to you @Key Values API.
__________________
B3none is offline
ThatOneGuy
Veteran Member
Join Date: Jul 2012
Location: Oregon, USA
Old 04-22-2017 , 02:26   Re: keyvalues
Reply With Quote #3

Each "key" must be unique for each section. Redo your setup as:

PHP Code:
"MyFile"
{
    
"general"
    
{
        
"Some Setup Name"
        
{
            
"steamid"        "value1"
        
}
        
        
"Another Setup Name"
        
{
            
"steamid"        "value2"
        
}
        
        
"Blah"
        
{
            
"steamid"        "value3"
        
}
    }

This puts each in their own setup. Then, you just need to work down to that level. Check out the links the previous poster put up for how to traverse the kv tree and combine with the wiki.
__________________

Last edited by ThatOneGuy; 04-22-2017 at 02:27.
ThatOneGuy is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 04-22-2017 , 03:14   Re: keyvalues
Reply With Quote #4

Updater is able to handle multiple keys with the same name within the same subkey. Second post, section titled "Update File Format."

Maybe see how he did it?
__________________
ddhoward is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 04-22-2017 , 04:53   Re: keyvalues
Reply With Quote #5

Quote:
Originally Posted by ddhoward View Post
Updater is able to handle multiple keys with the same name within the same subkey. Second post, section titled "Update File Format."

Maybe see how he did it?
Updater uses SMC, not KeyValues.
__________________
asherkin is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 04-22-2017 , 08:32   Re: keyvalues
Reply With Quote #6

Quote:
Originally Posted by ThatOneGuy View Post
Each "key" must be unique for each section.
This is not true. However, if you use the same key you will have no choice but to iterate over them since you can't just jump to the one you want.
Fyren is offline
Battousai-sama
Veteran Member
Join Date: Jul 2007
Old 04-22-2017 , 14:46   Re: keyvalues
Reply With Quote #7

@b3none, thats pretty much same as the other wiki i dont really understand how they work tried reading plugins to see how they use it, every1 has their own method of usage which makes it even more confusing

@TOG, even if i wan store all thats in that setup i have stated in an array[][]?

@ddh, isnt update to update plugins or something o.o? dont see connection with storing keyvalues into arrays and using them

@Fyren, iterate as in store all of it and read for specific part ya? or u meant something else
__________________
Battousai-sama is offline
Send a message via MSN to Battousai-sama
ThatOneGuy
Veteran Member
Join Date: Jul 2012
Location: Oregon, USA
Old 04-22-2017 , 14:59   Re: keyvalues
Reply With Quote #8

Quote:
Originally Posted by Fyren View Post
This is not true. However, if you use the same key you will have no choice but to iterate over them since you can't just jump to the one you want.
Good point.
__________________
ThatOneGuy is offline
ambn
Veteran Member
Join Date: Feb 2015
Location: Fun servers
Old 04-22-2017 , 15:15   Re: keyvalues
Reply With Quote #9

PHP Code:
stock void GetKeyData(char SteamId[32], char[] KvPath)
{
    
char FoundSteamId[32];
    
Handle kv CreateKeyValues("MyFiles");
    
FileToKeyvalues(kvKvPath);
    if(
KvJumpToKey(kvgeneralfalse))
    {
        
KvGotoFirstSubKey(kvfalse);
        do
        {
            
KvGetSectionName(kvFoundSteamIdsizeof(FoundSteamId));
            if(
StrEqual(FoundSteamIdSteamId))
            {
                
char Value[32];
                
KvGetString(kvFoundSteamIdValuesizeof(Value));
                
PrintToServer("[SM] The value of kv file is %s"Value);
                break;
            }
            else
                continue;
        }
        while(
KvGotoNextKey(kv));
    }

I'm not sure if it's gonna work or not cause it's my first time did things like this
__________________

Last edited by ambn; 04-22-2017 at 15:19.
ambn is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 04-22-2017 , 17:17   Re: keyvalues
Reply With Quote #10

Quote:
Originally Posted by Battousai-sama View Post
@ddh, isnt update to update plugins or something o.o? dont see connection with storing keyvalues into arrays and using them
Did you even look at the part of the post that I mentioned? This is how an updater txt file is formatted:

PHP Code:
"Updater"
{
    
"Information"
    
{
        
"Version"
        
{
            
"Latest"    "1.0.1"
        
}
        
        
"Notes"    "More info @ www.sourcemod.net. Changes in 1.0.1:"
        "Notes"    "Added new Batman model"
        "Notes"    "Minor code changes"
    
}
    
    
"Files"
    
{
        
"Plugin"    "Path_SM/plugins/myplugin.smx"
        "Plugin"    "Path_SM/translations/myplugin.phrases.txt"
        "Plugin"    "Path_SM/translations/ru/myplugin.phrases.txt"
        "Plugin"    "Path_Mod/models/characters/batman.mdl"
        "Plugin"    "Path_Mod/materials/models/characters/batman.vmt"
        
        "Source"    "Path_SM/scripting/myplugin.sp"
    
}

My suggestion was to see how the Updater plugin itself parses this information. (As asherkin pointed out, Updater uses SMC, which is similar but not identical to KeyValues.)
__________________

Last edited by ddhoward; 04-22-2017 at 17:20.
ddhoward 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 02:22.


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