Raised This Month: $ Target: $400
 0% 

Add two KeyValue files together


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 04-30-2015 , 11:43   Re: Add two KeyValue files together
Reply With Quote #1

Here are the steps I would go about merging those:
  • Load the files into KeyValues handles A and B.
  • (Optional) Create another KeyValues handle for the merge if you need to keep the original handles intact.
  • Iterate over A keys using GotoFirstSubKey() and GotoNextKey(), grabbing the current key using GetSectionName()
  • Check if A's key exists in B.
    • If yes, grab B stats and store the sum in the output handle (or A's handle if no output handle).
    • If no and are using an output handle, store A's data in the output handle.
  • Iterate over B keys same method as A.
  • If B's key does not exist in A, store B into the output handle (or A's handle if no output handle).

And there you will have them merged.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Phil25
AlliedModders Donor
Join Date: Feb 2015
Old 04-30-2015 , 13:51   Re: Add two KeyValue files together
Reply With Quote #2

Quote:
Originally Posted by Exolent[jNr] View Post
Here are the steps I would go about merging those:
  • Load the files into KeyValues handles A and B.
  • (Optional) Create another KeyValues handle for the merge if you need to keep the original handles intact.
  • Iterate over A keys using GotoFirstSubKey() and GotoNextKey(), grabbing the current key using GetSectionName()
  • Check if A's key exists in B.
    • If yes, grab B stats and store the sum in the output handle (or A's handle if no output handle).
    • If no and are using an output handle, store A's data in the output handle.
  • Iterate over B keys same method as A.
  • If B's key does not exist in A, store B into the output handle (or A's handle if no output handle).

And there you will have them merged.
Thank you for the plan, I guess I'll have a bit of a buisy night ;)


Quote:
Originally Posted by Dr. Greg House View Post
The biggest issue you have is being insane enough to store stats in a kv instead of doing it the appropriate way (that is dbs).
My general advice.
Yea, I thought this could be done a neater way, I just didn't know that yet. Seemed all right at the time when I started to write that plugin. We all had this young and crazy time... but on the upside, others can learn my mistakes. Would this be really such a pain in the future though? :s

And besides, although I'm trying to do this with files holding player statistics, I've never mentioned that in this thread (except for the examples). So it's kinda universal and might help others whatever they'll try to accomplish.
Phil25 is offline
Dr. Greg House
Professional Troll,
Part-Time Asshole
Join Date: Jun 2010
Old 04-30-2015 , 14:00   Re: Add two KeyValue files together
Reply With Quote #3

Quote:
Originally Posted by Phil25 View Post
Would this be really such a pain in the future though? :s
Yes.
__________________
Santa or Satan?

Watch out when you're paying people for private requests! Most stuff already exists and you can hardly assess the quality of what you'll get, and if it's worth the money.
Dr. Greg House 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 19:12.


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