AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved amxx 1.9 crash (https://forums.alliedmods.net/showthread.php?t=311413)

iceeedr 10-16-2018 23:12

amxx 1.9 crash
 
Hello, does anyone know why the code below crashes the sv? No log, clean crash.

PHP Code:

#include <amxmodx>
#include <amxmisc>

new Var1Var2Var3

public plugin_init()
{
    
bind_pcvar_num(create_cvar("var1_test","1", .description ""), Var1)
    
bind_pcvar_num(create_cvar("var2_test""1", .description ""), Var2)
    
bind_pcvar_num(create_cvar("var3_test""1", .description ""), Var3)
    
set_task_ex(3.0"Enabled", .flags SetTask_Once)
    
AutoExecConfig(.autoCreate true, .name "Test")
}

public 
Enabled()
{
    
set_pcvar_num(Var1,0)    
    
set_pcvar_num(Var20)
    
set_pcvar_num(Var30)



Arkshine 10-17-2018 03:43

Re: amxx 1.9 crash
 
You misunderstand the use of bind_pcvar_* natives.
They bind a cvar to a variable. Meaning that variable will contain the actual cvar's value in real time. This is NOT a cvar handle. You can't set a value from that.

To set a cvar with set_pcvar_num(), you still need to retrieve the handle from create_cvar() and using that value.
You can also use set_cvar_num(), it doesn't matter.

iceeedr 10-17-2018 08:21

Re: amxx 1.9 crash
 
Quote:

Originally Posted by Arkshine (Post 2620026)
You misunderstand the use of bind_pcvar_* natives.
They bind a cvar to a variable. Meaning that variable will contain the actual cvar's value in real time. This is NOT a cvar handle. You can't set a value from that.

To set a cvar with set_pcvar_num(), you still need to retrieve the handle from create_cvar() and using that value.
You can also use set_cvar_num(), it doesn't matter.

I had not really understood then, the correct use of the native bind_pcvar_ *, with the example quoted by me, how could I assign a value to pcvar? Or do I have to create just the pcvar with create_cvar and use it normally?

Kushfield 10-17-2018 08:48

Re: amxx 1.9 crash
 
Quote:

Originally Posted by iceeedr (Post 2620043)
I had not really understood then, the correct use of the native bind_pcvar_ *, with the example quoted by me, how could I assign a value to pcvar? Or do I have to create just the pcvar with create_cvar and use it normally?

That's right, if you need to change the cvar's value, you have to store the return value from create_cvar and pass that to the set_pcvar_* functions as you normally would.

The bind_pcvar_* functions just set the passed in variable to the cvar's value and keep it automatically updated. That saves you from using get_pcvar_*/get_cvar_* every time you need to use the cvar's value.

iceeedr 10-17-2018 08:52

Re: amxx 1.9 crash
 
Thanks for all the clarifications.


All times are GMT -4. The time now is 00:43.

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