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

ConVar's .BoolValue expected value


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Robotex
Junior Member
Join Date: Mar 2016
Old 04-28-2016 , 18:20   ConVar's .BoolValue expected value
Reply With Quote #1

What should be the value returned by the .BoolValue property getter when the related ConVar is 0.0<x<1.0?
I'm asking because I have seen some scripts (ex. SuperVersus) that use this snippet
Code:
ConVar TankHpMulti;
...
    TankHpMulti    = CreateConVar("director_tank_hpmulti","0.25","Tanks HP Multiplier (multi*(survivors-4)). Requires director_auto_difficulty 1", CVAR_FLAGS,true,0.00,true,1.00);
...
    if (TankHpMulti.BoolValue){   // if not 0
            int TankHP = RoundFloat(4000.0*TankHp_Multi);
            FindConVar("z_tank_health").IntValue = TankHP;
    }
However after I noticed that the last part of the code is never called despite director_tank_hpmulti > 0, I added some debug prints and have seen that any value < 1 (without counting 0) returns false.
Who is doing incorrectly there?

SourceMod 1.7.3-dev+5302,

Last edited by Robotex; 04-28-2016 at 18:21.
Robotex is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 04-28-2016 , 18:21   Re: ConVar's .BoolValue expected value
Reply With Quote #2

you should probably check if the ConVar's FloatValue is greater then 0
WildCard65 is offline
Robotex
Junior Member
Join Date: Mar 2016
Old 04-28-2016 , 18:38   Re: ConVar's .BoolValue expected value
Reply With Quote #3

Quote:
Originally Posted by WildCard65 View Post
you should probably check if the ConVar's FloatValue is greater then 0
.FloatValue is returning the expected value, however it's those .BoolValue s that are bugging me because the script I'm analyzing wasn't written by me and looking at the API documentation of SM it doesn't specify anything about when .BoolValue should return true and when it returns false, leaving it as an undefined behaviour in my eyes
Robotex is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 04-28-2016 , 19:06   Re: ConVar's .BoolValue expected value
Reply With Quote #4

.BoolValue, as well as other aspects of the transitional syntax, compiles to the same code as the old syntax. So it's the same as using:

https://sm.alliedmods.net/new-api/convars/GetConVarBool
https://sm.alliedmods.net/new-api/convars/SetConVarBool

From what I remember from what I've experienced, the only values that GetConVarBool should evaluate to FALSE are 0 (and its equivalents, 0.0, -0.0, etc.) as well as actually putting the word "false" into the ConVar. None of that is true.
__________________

Last edited by ddhoward; 04-29-2016 at 04:24.
ddhoward is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 04-29-2016 , 02:48   Re: ConVar's .BoolValue expected value
Reply With Quote #5

That code is broken anyway since its multiplying by the ConVar variable itself, probably missing a FloatValue.

As for BoolValue, the engine calculates it from IntValue, which is truncated from FloatValue, so: 0.9 ~= 0 ~= false, 1.1 ~= 1 ~= true.
__________________
asherkin is offline
Robotex
Junior Member
Join Date: Mar 2016
Old 04-29-2016 , 03:58   Re: ConVar's .BoolValue expected value
Reply With Quote #6

Quote:
Originally Posted by asherkin View Post
That code is broken anyway since its multiplying by the ConVar variable itself, probably missing a FloatValue.
The float value was declared right above the if expression as
Code:
float TankHp_Multi = 1 + TankHpMulti.FloatValue*extrasurvivors;
and I didn't include it in my post for sake of clarity.
I agree that the similar name is confusing but again I didn't write the plugin.

Quote:
Originally Posted by asherkin View Post
As for BoolValue, the engine calculates it from IntValue, which is truncated from FloatValue, so: 0.9 ~= 0 ~= false, 1.1 ~= 1 ~= true.
This is all what I needed to know, thanks.

Last edited by Robotex; 04-29-2016 at 04:06.
Robotex 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 08:17.


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