AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Float Cvar Tag mismatch Warning (https://forums.alliedmods.net/showthread.php?t=344869)

Cuttlas 12-14-2023 15:00

Float Cvar Tag mismatch Warning
 
I have a float variable for setting a delay for set_task:

PHP Code:

new Float:RespawnDelay 

and I will set it in plugin_init (which gives me tag mismatch warning):

PHP Code:

RespawnDelay register_cvar("respawn_delay""1.5"

also used it in set_task like this (which gives me tag mismatch warning):

PHP Code:

set_task(get_pcvar_float(RespawnDelay), "ReviveIt" Victim

and also somewhere I check for its value (which gives me tag mismatch warning):

PHP Code:

if (get_pcvar_float(RespawnDelay) > 30)
    
RespawnDelay 30 


how to avoid tag mismatch warning for a float cvar?

WATCH_D0GS UNITED 12-14-2023 15:26

Re: Float Cvar Tag mismatch Warning
 
Change to the following:

PHP Code:

new RespawnDelay 

PHP Code:

new Float:Delay get_pcvar_float(RespawnDelay)
set_task(Delay "ReviveIt" Victim

PHP Code:

    if (Delay 30.0)
        
RespawnDelay 30.0 


Bugsy 12-14-2023 19:17

Re: Float Cvar Tag mismatch Warning
 
You can also consider using floatclamp(), to ensure the cvar is between a min/max.

PHP Code:

//This will ensure the value is between 5.0 and 30.0
RespawnDelay floatclampget_pcvar_floatRespawnDelay ) , 5.0 30.0 ); 


DJEarthQuake 12-14-2023 20:46

Re: Float Cvar Tag mismatch Warning
 
Quote:

Originally Posted by Cuttlas (Post 2814474)

PHP Code:

if (get_pcvar_float(RespawnDelay) > 30)
    
RespawnDelay 30 


30.0

fysiks 12-14-2023 23:59

Re: Float Cvar Tag mismatch Warning
 
I think you should look at how the return value of register_cvar() actually works. Find some approved plugins that use this return value. Hint: it is a cvar pointer.

101 12-15-2023 01:52

Re: Float Cvar Tag mismatch Warning
 
That because u have stored a pointer in a float variable , Look at this : register_cvar
u can see at the end of the page that register_cvar doesn't return any float or int value , it returns an <address/pointer> that shouldn't be stored or handled by a float variable .

PHP Code:

new RespawnDelay ;  //this will be a POINTER 
RespawnDelay register_cvar("respawn_delay""1.5");  //our POINTER now is pointing to this cvar 

to get the value of the previous cvar , u can do this :
PHP Code:

get_cvar_float("respawn_delay"); // this will return a float value (and this call is usually used If u know the Cvar Name) 

Or This :
PHP Code:

get_pcvar_float(RespawnDelay); // pcvar means : dereference *(this pointer) , and this will return a float value that the given pointer was pointing at (and this call is usually used if u have stored the cvar in a KNOWN pointer) 


Summary :

- Each Existing CVAR has a value and has a unique pointer .
- Value of Cvar might be (integer , float , or string)
PHP Code:

In your case : the value of ur cvar was Float because u assigned "1.5" which is a float 

- get_cvar means GET the Value .
PHP Code:

//float :
get_cvar_float("respawn_delay");
//int :
get_cvar_num("mp_timeleft");
//string :
new Text[32];
get_cvar_string("hostname"Textcharsmax(Text)); 

- get_pcvar means dereference a Given Pointer to get the value that Pointer was pointing at .
PHP Code:

//float :
get_pcvar_float(RespawnDelay);   // Note That RespawnDelay should be a pointer 
//int :
get_pcvar_num(get_cvar_pointer("sv_maxplayers")); // Twisted way to get the value (dereferencing a given pointer will return the value itself)
//string :
new Text[32];
get_pcvar_string(get_cvar_pointer("hostname"), Textcharsmax(Text)); // Twisted 

-Dereferencing a Pointer should return the Value itself.
-Value of a Value should also return the Value itself .
-Value of a Pointer OR Pointer of a Value will Cuze problems (so try to avoid this) :
PHP Code:

get_pcvar_float("respawn_delay");  // this is Wrong and it means ( dereference this pointer (?!string?!) )
get_cvar_float(RespawnDelay);  // this is also Wrong and it means (get the float value from cvars array that match this string (?!Pointer?!) ) 

I think it wouldn't be a disaster if something like this was found in here : https://www.amxmodx.org

Cuttlas 12-15-2023 08:23

Re: Float Cvar Tag mismatch Warning
 
thank you, brothers, specially @101, I reduced about 6 warnings,
but still there is another warning:

PHP Code:

new RespawnDelay

public plugin_init(){
        
RespawnDelay register_cvar("respawn_delay""1.5")
    if (
get_pcvar_float(RespawnDelay) < 0)
        
RespawnDelay 1.5


here it will give tag mismatch warning on the last line (RespawnDelay = 1.5)

101 12-15-2023 09:26

Re: Float Cvar Tag mismatch Warning
 
Quote:

Originally Posted by Cuttlas (Post 2814503)
PHP Code:


public plugin_init(){
        
RespawnDelay register_cvar("respawn_delay""1.5")
    if (
get_pcvar_float(RespawnDelay) < 0)
        
RespawnDelay 1.5



The last line is totally wrong , since RespawnDelay is a pointer/address and not a float variable .
it is just something STRANGE that <points at the float value> and <its not the float value itself> .

it looks like this : RespawnDelay ☞ float (it contains an address inside and not a value , it just tracks the float value by carrying its address , So it should not be treated as float or int) its something totally different .
BTW , you can use this instead :
PHP Code:

public plugin_init()
{
    
RespawnDelay register_cvar("respawn_delay""1.5");
    if (
get_pcvar_float(RespawnDelay) <= 0)
    {
        
set_pcvar_float(RespawnDelay,1.5);  // it means :change the value <that RespawnDelay is pointing at> TO 1.5
    
}


OR :
PHP Code:

public plugin_init()
{
    
RespawnDelay register_cvar("respawn_delay""1.5");
    if (
get_pcvar_float(RespawnDelay) <= 0)
    {
        
set_cvar_float("respawn_delay",1.5);  // search for the float value by a given cvar name and change the value to 1.5 , in this case :  RespawnDelay is just watching and still points at the same float address <because its a pointer and its main mission is tracking the address of a specified variable>
    
}


The question is : Which one is faster and more efficient ?
according to these documentations : https://www.amxmodx.org/api/cvars/set_cvar_float
set_pcvar_float is faster and more efficient .

RespawnDelay ☞ float value

fysiks 12-15-2023 23:38

Re: Float Cvar Tag mismatch Warning
 
This is why I said you should learn how the pointer for cvars actually work. I you learn the reason behind how they work, you'll have less issues and be able to create plugins better and quicker.

Here is an existing tutorial about cvars: https://forums.alliedmods.net/showthread.php?t=85316. Also, as stated before, you can look at existing plugins to see how to use some of these functions.

Also, here is a list of a bunch of tutorials that you may want to search when you're having issues with your own code: https://forums.alliedmods.net/showthread.php?t=172936.

101 12-16-2023 03:59

Re: Float Cvar Tag mismatch Warning
 
Quote:

Originally Posted by Bugsy (Post 2814480)
You can also consider using floatclamp(), to ensure the cvar is between a min/max.

PHP Code:

//This will ensure the value is between 5.0 and 30.0
RespawnDelay floatclampget_pcvar_floatRespawnDelay ) , 5.0 30.0 ); 


floatclamp :

This function doesn't work as desire , it seems like get_pcvar_float( RespawnDelay ) return a fake value or a copy of the original value so <floatclamp>won't be able to restrict the actual float value of the given cvar between 5.0 and 30.0 .
BTW , I think that RespawnDelay is a pointer while floatclamp return a float value that shouldn't be stored in a pointer .

After many retries , I now realized that floatclamp(Float:X , min , max) does't change the actual value of X , it just checks :
* if X in between mix and max THEN return X .
* if X > max THEN return max .
* if X < min THEN return min .
PHP Code:

#include <amxmodx>

new RespawnDelay;
public 
plugin_init()
{
    
RespawnDelay register_cvar("respawn_delay""1.5");
    
set_task(3.0,"Print_Test",100);
}

public 
Print_Test()
{
    
set_pcvar_floatRespawnDelay 50.0 );
    
log_amx("Clamped Cvar Value=%f",floatclampget_pcvar_floatRespawnDelay ) ,5.0 30.0)); // result 30.0
    
    
set_pcvar_floatRespawnDelay 10.0 );
    
log_amx("Clamped Cvar Value=%f",floatclampget_pcvar_floatRespawnDelay ) ,5.0 30.0));// result 10.0
    
    
set_pcvar_floatRespawnDelay , -1.0 );
    
log_amx("Clamped Cvar Value=%f",floatclampget_pcvar_floatRespawnDelay ) ,5.0 30.0));// result 5.0
    
    
log_amx("Actual Cvar Value=%f",get_pcvar_floatRespawnDelay));// result -1.0 (the last modified value)


So how can we restrict a cvar value between Min and Max with/without using this function :
PHP Code:

create_cvar(const name[], const string[], flags FCVAR_NONE, const description[] = ""bool:has_min falseFloat:min_val 0.0bool:has_max falseFloat:max_val 0.0); 

It throws an error while compiling : undefined symbol "create_cvar"

Regrads


All times are GMT -4. The time now is 16:31.

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