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

Float Cvar Tag mismatch Warning


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Cuttlas
Senior Member
Join Date: Jan 2015
Old 12-14-2023 , 15:00   Float Cvar Tag mismatch Warning
Reply With Quote #1

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?
__________________
To Infinity n Beyond

Last edited by Cuttlas; 12-14-2023 at 15:01.
Cuttlas is offline
WATCH_D0GS UNITED
Senior Member
Join Date: Jan 2023
Old 12-14-2023 , 15:26   Re: Float Cvar Tag mismatch Warning
Reply With Quote #2

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 
__________________
💻Know Our New Blog👄
🔗tube2downs.blogspot.com

Last edited by WATCH_D0GS UNITED; 12-14-2023 at 15:31.
WATCH_D0GS UNITED is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-14-2023 , 19:17   Re: Float Cvar Tag mismatch Warning
Reply With Quote #3

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 ); 
__________________
Bugsy is offline
DJEarthQuake
Veteran Member
Join Date: Jan 2014
Location: Astral planes
Old 12-14-2023 , 20:46   Re: Float Cvar Tag mismatch Warning
Reply With Quote #4

Quote:
Originally Posted by Cuttlas View Post

PHP Code:
if (get_pcvar_float(RespawnDelay) > 30)
    
RespawnDelay 30 
30.0
DJEarthQuake is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-14-2023 , 23:59   Re: Float Cvar Tag mismatch Warning
Reply With Quote #5

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.
__________________
fysiks is offline
101
Member
Join Date: Nov 2023
Old 12-15-2023 , 01:52   Re: Float Cvar Tag mismatch Warning
Reply With Quote #6

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

Last edited by 101; 12-16-2023 at 04:19. Reason: update information
101 is offline
Cuttlas
Senior Member
Join Date: Jan 2015
Old 12-15-2023 , 08:23   Re: Float Cvar Tag mismatch Warning
Reply With Quote #7

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)
__________________
To Infinity n Beyond

Last edited by Cuttlas; 12-15-2023 at 08:30.
Cuttlas is offline
101
Member
Join Date: Nov 2023
Old 12-15-2023 , 09:26   Re: Float Cvar Tag mismatch Warning
Reply With Quote #8

Quote:
Originally Posted by Cuttlas View Post
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

Last edited by 101; 12-15-2023 at 13:24.
101 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-15-2023 , 23:38   Re: Float Cvar Tag mismatch Warning
Reply With Quote #9

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.
__________________

Last edited by fysiks; 12-15-2023 at 23:42.
fysiks is offline
101
Member
Join Date: Nov 2023
Old 12-16-2023 , 03:59   Re: Float Cvar Tag mismatch Warning
Reply With Quote #10

Quote:
Originally Posted by Bugsy View Post
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
101 is offline
Old 12-16-2023, 04:15
101
This message has been deleted by 101.
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 12:11.


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