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

Cvars in an array with loop


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 08-04-2018 , 23:20   Cvars in an array with loop
Reply With Quote #1

I wanted to use a loop that can go through multiple cvars. I have created 12 cvars each starting at 1 till 12. Why is there no increment?

PHP Code:
#include <sourcemod>

ConVar Cvar[12];

public 
void OnPluginStart()
{
    
Cvar[0]         = CreateConVar"l4d2_cvar1",    "1""");
    
Cvar[1]        = CreateConVar"l4d2_cvar2",     "2""");
    
Cvar[2]         = CreateConVar"l4d2_cvar3",     "3""");
    
Cvar[3]        = CreateConVar"l4d2_cvar4",    "4""");
    
Cvar[4]        = CreateConVar"l4d2_cvar5",    "5""");
    
Cvar[5]        = CreateConVar"l4d2_cvar6",    "6""");
    
Cvar[6]        = CreateConVar"l4d2_cvar7",    "7""");
    
Cvar[7]        = CreateConVar"l4d2_cvar8",    "8""");
    
Cvar[8]        = CreateConVar"l4d2_cvar9",    "9""");
    
Cvar[9]        = CreateConVar"l4d2_cvar10",    "10""");
    
Cvar[10]        = CreateConVar"l4d2_cvar11",    "11""");
    
Cvar[11]        = CreateConVar"l4d2_cvar12",    "12""");

    
RegAdminCmd"sm_cvar"Command_CVARFUNCTIONADMFLAG_KICK"Testing the cvar loop" );
}

void Command_CVARFUNCTION()
{
    
int len sizeof(Cvar);
    
    for(
int xlenx++)
    {
        for(
int iCvar[x].IntValuei++ )
        {
            
LogAcitivity("CVAR Num: %d"Cvar[x].IntValue);
        }
    }

    return 
Plugin_Handled;

This is the output.

PHP Code:
L 08/04/2018 23:00:20: [cvar.smxCVAR Num1
L 08
/04/2018 23:00:20: [cvar.smxCVAR Num1
L 08
/04/2018 23:00:20: [cvar.smxCVAR Num1
L 08
/04/2018 23:00:21: [cvar.smxCVAR Num1
L 08
/04/2018 23:00:21: [cvar.smxCVAR Num1
L 08
/04/2018 23:00:21: [cvar.smxCVAR Num1
L 08
/04/2018 23:00:21: [cvar.smxCVAR Num1
L 08
/04/2018 23:00:21: [cvar.smxCVAR Num1
L 08
/04/2018 23:00:21: [cvar.smxCVAR Num1
L 08
/04/2018 23:00:21: [cvar.smxCVAR Num1
L 08
/04/2018 23:00:21: [cvar.smxCVAR Num1
L 08
/04/2018 23:00:21: [cvar.smxCVAR Num
__________________
Spirit_12 is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 08-05-2018 , 00:00   Re: Cvars in an array with loop
Reply With Quote #2

try it with this for debugging

LogAcitivity("CVAR Num: %d, Value %d", x, Cvar[x].IntValue);
__________________
ddhoward is offline
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 08-05-2018 , 00:15   Re: Cvars in an array with loop
Reply With Quote #3

Quote:
Originally Posted by ddhoward View Post
try it with this for debugging

LogAcitivity("CVAR Num: %d, Value %d", x, Cvar[x].IntValue);
PHP Code:

L 08
/05/2018 00:09:49: [Cvar.smxCVAR Num0Value1
L 08
/05/2018 00:09:49: [Cvar.smxCVAR Num1Value1
L 08
/05/2018 00:09:49: [Cvar.smxCVAR Num2Value1
L 08
/05/2018 00:09:49: [Cvar.smxCVAR Num3Value1
L 08
/05/2018 00:09:49: [Cvar.smxCVAR Num4Value1
L 08
/05/2018 00:09:49: [Cvar.smxCVAR Num5Value1
L 08
/05/2018 00:09:49: [Cvar.smxCVAR Num6Value1
L 08
/05/2018 00:09:49: [Cvar.smxCVAR Num7Value1
L 08
/05/2018 00:09:49: [Cvar.smxCVAR Num8Value1
L 08
/05/2018 00:09:49: [Cvar.smxCVAR Num9Value1
L 08
/05/2018 00:09:50: [Cvar.smxCVAR Num10Value1
L 08
/05/2018 00:09:50: [Cvar.smxCVAR Num11Value
This doesn't add up.
__________________
Spirit_12 is offline
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 08-05-2018 , 00:28   Re: Cvars in an array with loop
Reply With Quote #4

I just ran a simple cvar value command and it gave me wrong output.

PHP Code:
public Action Command_SMCvar(int clientint args)
{
    for (
int isizeof(Cvar_MeleeWeapon); i++)
    {
        
PrintToChatclient"CVAR: %d value: %d"iCvar[i].IntValue);
    }
    return 
Plugin_Handled;

Code above resulted in the following output. What am I doing wrong here?

PHP Code:
CVAR0 value1
CVAR
1 value1
CVAR
2 value1
CVAR
3 value1
CVAR
4 value1
CVAR
5 value1
CVAR
6 value1
CVAR
7 value1
CVAR
8 value1
CVAR
9 value1
CVAR
10 value1
CVAR
11 value
__________________
Spirit_12 is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 08-05-2018 , 00:39   Re: Cvars in an array with loop
Reply With Quote #5

The output in the above post would indicate that all the cvars are being looped through appropriately, and their values all == 1.
__________________

Last edited by ddhoward; 08-05-2018 at 00:40.
ddhoward is offline
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 08-05-2018 , 00:43   Re: Cvars in an array with loop
Reply With Quote #6

Quote:
Originally Posted by ddhoward View Post
The output in the above post would indicate that all the cvars are being looped through appropriately, and their values all == 1.
Exactly, but the values are not 1. Like I said the values are as listed above starting at 1 and ending at 12.
__________________
Spirit_12 is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 08-05-2018 , 00:45   Re: Cvars in an array with loop
Reply With Quote #7

Verify that via sm_cvar
__________________
ddhoward is offline
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 08-05-2018 , 01:06   Re: Cvars in an array with loop
Reply With Quote #8

PHP Code:
[SMValue of cvar "l4d2_cvar12""12" 
__________________
Spirit_12 is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 08-05-2018 , 08:36   Re: Cvars in an array with loop
Reply With Quote #9

The code you gave in your first post is garbage. After fixing the straight up errors, it prints what I'd expect, which is 1, 2, 2, 3, 3, 3, 4, 4, 4, 4... up to 12.

Whatever your problem is, it's outside what you've given. The code in your second reply is not a complete example so I can't tell you what you've done wrong there.
Fyren is offline
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 08-05-2018 , 13:27   Re: Cvars in an array with loop
Reply With Quote #10

Can you paste your code?

Also, since my code in the first post is not very good which I assumed it is. Can you show me how to loop through all cvars in an array?

I need to check if cvar is at least 1 and then the value to spawn items. What would be the best approach to it?
__________________
Spirit_12 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 17:34.


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