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

L4D2 ... How to iterate through CVars


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Keeper
Senior Member
Join Date: Nov 2006
Old 08-24-2012 , 20:28   L4D2 ... How to iterate through CVars
Reply With Quote #1

I am looking to update a plugin to work with newer games. I am stuck on iterating through the CVars. I saw the "Porting to Left 4 Dead" article but it doesn't seem to work. I have converted other parts to hit specific cvars/concommands, but there is one place I need to iterate through.

Any help would be appreciated!

Thanks,
Keeper
Keeper is offline
Keeper
Senior Member
Join Date: Nov 2006
Old 08-24-2012 , 21:39   Re: L4D2 ... How to iterate through CVars
Reply With Quote #2

Nevermind ... I got it working!
Keeper is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 08-25-2012 , 00:33   Re: L4D2 ... How to iterate through CVars
Reply With Quote #3

Quote:
Originally Posted by Keeper View Post
Nevermind ... I got it working!
Yeah... very helpful.
__________________
Silvers is offline
Keeper
Senior Member
Join Date: Nov 2006
Old 08-25-2012 , 08:19   Re: L4D2 ... How to iterate through CVars
Reply With Quote #4

LOL ... well I didn't know if it was something that was already known and I was just being daft.

Code:
    ConCommandBase *pPtr = NULL;
    ICvar::Iterator *iter = new ICvar::Iterator(icvar);
    if (iter) iter->SetFirst(); // added this to make it work, otherwise it's never valid
    while (iter->IsValid())
    {
        pPtr = iter->Get();
        // do other code here
        iter->Next();
    }
I was missing the call to SetFirst(). iter was defined, but I couldn't figure out why it was never valid.

Last edited by Keeper; 08-25-2012 at 08:20.
Keeper is offline
Chrisber
AlliedModders Donor
Join Date: Jul 2007
Location: localhost
Old 08-25-2012 , 10:50   Re: L4D2 ... How to iterate through CVars
Reply With Quote #5

Please use RAII
Chrisber is offline
Keeper
Senior Member
Join Date: Nov 2006
Old 08-25-2012 , 11:27   Re: L4D2 ... How to iterate through CVars
Reply With Quote #6

Quote:
Originally Posted by Chrisber View Post
Please use RAII
I'm not sure what that has to do with an example of how to iterate through CVars.
Keeper is offline
Old and Slow
Senior Member
Join Date: May 2005
Location: Arlington, Texas
Old 08-25-2012 , 19:34   Re: L4D2 ... How to iterate through CVars
Reply With Quote #7

Quote:
Originally Posted by Keeper View Post
LOL ... well I didn't know if it was something that was already known and I was just being daft.

Code:
    ConCommandBase *pPtr = NULL;
    ICvar::Iterator *iter = new ICvar::Iterator(icvar);
    if (iter) iter->SetFirst(); // added this to make it work, otherwise it's never valid
    while (iter->IsValid())
    {
        pPtr = iter->Get();
        // do other code here
        iter->Next();
    }
I was missing the call to SetFirst(). iter was defined, but I couldn't figure out why it was never valid.
I didn't use an iterator but used GetCommands() to establish the ConCommandBase pointer.
The CS:GO version doesn't have GetCommands() not but FindCommandBase(s) where "s" is a string argument. What whould the string be to get it to work as before?

I may get impatient and just use the iterator but I wanted to "fix" the existing method.

Thanks.
__________________
.......Chuck |TxA| Old and Slow [AARP]
Old and Slow is offline
Chrisber
AlliedModders Donor
Join Date: Jul 2007
Location: localhost
Old 08-25-2012 , 19:48   Re: L4D2 ... How to iterate through CVars
Reply With Quote #8

Quote:
Originally Posted by Keeper View Post
I'm not sure what that has to do with an example of how to iterate through CVars.
It does not have to do anything with that. But well, it's not the C++ way of doing it "smoothly".
Chrisber is offline
Keeper
Senior Member
Join Date: Nov 2006
Old 08-26-2012 , 00:19   Re: L4D2 ... How to iterate through CVars
Reply With Quote #9

Quote:
Originally Posted by Old and Slow View Post
I didn't use an iterator but used GetCommands() to establish the ConCommandBase pointer.
The CS:GO version doesn't have GetCommands() not but FindCommandBase(s) where "s" is a string argument. What whould the string be to get it to work as before?

I may get impatient and just use the iterator but I wanted to "fix" the existing method.

Thanks.
There are many places where I just grabbed the ConCommands by name. There's only one place where I iterate through. The only way I've seen to do this is by this method. I don't know if there is a reliable "first" ConCommand to use as "s".
Keeper is offline
Old and Slow
Senior Member
Join Date: May 2005
Location: Arlington, Texas
Old 08-26-2012 , 04:24   Re: L4D2 ... How to iterate through CVars
Reply With Quote #10

Quote:
Originally Posted by Keeper View Post
There are many places where I just grabbed the ConCommands by name. There's only one place where I iterate through. The only way I've seen to do this is by this method. I don't know if there is a reliable "first" ConCommand to use as "s".
Yeah, for what I am doing, I just need to grab a couple of them by name. I have one spot (a debug plug-in) where I list out all the convar commands and variables to a file for reference.
__________________
.......Chuck |TxA| Old and Slow [AARP]
Old and Slow 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 06:04.


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