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

getting cvar string/num, which is faster?


Post New Thread Reply   
 
Thread Tools Display Modes
Desikac
Senior Member
Join Date: Apr 2010
Location: Serbia
Old 08-29-2011 , 06:20   Re: getting cvar string/num, which is faster?
Reply With Quote #11

Quote:
Originally Posted by OvidiuS View Post
he has around 22 cvars xD
anything more adjustable?
25
Is this a good method (to handle 25 cvars)?
PHP Code:
#include <amxmodx>

new cvars[25]

public 
plugin_init() {
    
cvars[0] = register_cvar("mycvar""1")
    
cvars[1] = register_cvar("mycvar2""8")
    
cvars[2] = register_cvar("mycvar3""55")
    
cvars[3] = register_cvar("mycvar4""dsa")
    
cvars[4] = register_cvar("mycvar5""0")
    
cvars[5] = register_cvar("mycvar6""4")
// ...
    
cvars[24] = register_cvar("mycvar25""qwerty")
}

public 
get_values() {
    new 
sVal[32]
    
get_pcvar_string(cvars[3], sValcharsmax(sVal))
    
    new 
iVal get_pcvar_num(cvars[5])

Desikac is offline
Send a message via MSN to Desikac Send a message via Skype™ to Desikac
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-29-2011 , 10:14   Re: getting cvar string/num, which is faster?
Reply With Quote #12

PHP Code:
#include <amxmodx>

enum _:Cvar {
    
Cvar_1,
    
Cvar_2,
    
Cvar_3,
    
//...
    
Cvar_22
};

new const 
g_cvarName[Cvar][] = {
    
"cvar_1",
    
"cvar_2",
    
"cvar_3",
    
//...
    
"cvar_22"
};

new const 
g_cvarDefaultValue[Cvar][] = {
    
"1",
    
"1",
    
"1",
    
//...
    
"1"
};

new 
g_cvarPointer[Cvar];

public 
plugin_init() {
    for(new 
0Cvari++) {
        
g_cvarPointer[i] = register_cvar(g_cvarName[i], g_cvarDefaultValue[i]);
    }
}

// ...

new value get_pcvar_num(g_cvarPointer[Cvar_22]); 
Naming the "cvar_*" to proper names is recommended for more readable code.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Desikac
Senior Member
Join Date: Apr 2010
Location: Serbia
Old 08-29-2011 , 11:40   Re: getting cvar string/num, which is faster?
Reply With Quote #13

Your code does the same thing as mine.
Desikac is offline
Send a message via MSN to Desikac Send a message via Skype™ to Desikac
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-29-2011 , 11:51   Re: getting cvar string/num, which is faster?
Reply With Quote #14

Quote:
Originally Posted by Desikac View Post
Your code does the same thing as mine.
Mine's more organized, easier to add/delete cvars, and easier to read than using get_pcvar_num(cvars[0])
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 09-05-2011 , 05:38   Re: getting cvar string/num, which is faster?
Reply With Quote #15

Quote:
Originally Posted by OvidiuS View Post
he has around 22 cvars xD
anything more adjustable?
https://forums.alliedmods.net/showth...CacheCvarValue

And now ?
__________________
Arkshine 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 00:43.


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